quit = '\0';
while (quit != 'q')
{
cout << "Hello ! This is a console app." << endl;
cout << "To create a console, go to Project Options and select" << endl;
cout << "\'Win32 Console\'." << endl;
cout << "Press q to quit " << endl;
cin >> quit;
}
return 0;
}
Out:
编译器: Default compiler
Building Makefile: "C:\Dev-Cpp\Examples\Hello\Makefile.win"
执行 make...
make.exe -f "C:\Dev-Cpp\Examples\Hello\Makefile.win" all
g++.exe -c Hello.cpp -o Hello.o -I"C:/DEV-CPP/include" -I"C:/DEV-CPP/include/c++" -I"C:/DEV-CPP/include" Hello.cpp:1:22: iostream.h: No such file or directory
Hello.cpp: In function `int main(int, char**)':
Hello.cpp:12: `cout' undeclared (first use this function)
Hello.cpp:12: (Each undeclared identifier is reported only once for each
function it appears in.)
Hello.cpp:12: `endl' undeclared (first use this function)
Hello.cpp:16: `cin' undeclared (first use this function)g++.exe Hello.o -o "Hello.exe" -L"C:/DEV-CPP/lib" -I"C:/DEV-CPP/include" -I"C:/DEV-CPP/include/c++" -I"C:/DEV-CPP/include" G__~1.EXE: Hello.o: No such file or directory
G__~1.EXE: no input files执行结束
Three approaches to solve:
A1. using namespace std; //easiest way but easily clashes with other user-defined namespaces
A2. std::cout //regular way but it can be rather troublesome
A3. using std::cout; //The best way keeping the balance between A1 & A2