I write a simple program, to run in DOS mode. Everything works under emulated console in Win XP / Vista / Seven, but not in DOS. The error says:
this program caonnot be run in DOS mode
_strdate
_strtime
time.h
_strdate was not declared in this scope
gotoxy
#include <windows.h>
void gotoxy(int x, int y)
{
COORD position;
position.X = x; position.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), position);
}
gotoxy
time();
_strdate();
_strtime();
time_t rawtime;
struct tm * timeinfo;
char buffer [20];
time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (buffer,80,"%Y.%m.%d %H:%M:%S\0",timeinfo);
string myTime(buffer);
gotoxy
From the sound of things, you're currently compiling a Windows console program. Even though it's a console program, it still needs Windows to run.
To compile a program to run on real DOS, you'll need to find a (probably really old) compiler and (especially) linker that targets DOS and can produce DOS MZ executables. The last Microsoft compiler to target MS-DOS was VC++ 1.52c. If memory serves, Borland continued to target DOS somewhat later, up through something like Broland C++ 5 or so.
I believe if you check the Digital Mars web site, he may still have a C++ compiler available that targets DOS. Otherwise, you're going to be stuck looking for something used and quite old.
Edit: looking at other answers reminded me of DJGPP and OpenWatcom. My apologies for not mentioning them previously.
Be aware that from a C++ viewpoint, Borland and Microsoft are really old compilers -- they don't do namespaces at all, and template support varies from nonexistent in the Microsoft compiler to mediocre in Borland's. DJGPP is basically a DOS extender to which gcc has been ported; the degree to which it's out of date (or modern) will depend on which version of gcc is involved. The Digital Mars compiler is somewhat more modern than the Borland one if I'm not mistaken, but Walter Bright now spends most of his time working on D instead of C++, so the C++ compiler doesn't really compete with gcc, or MSVC, not to mention something like Comeau or Intel that's based on the EDG front-end.