I am currently experimenting with Cygwin, just started trying it today when I encountered this problem.
This is my MSVS 2010 C++ code for testing:
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
cout << "Hello, world!" << endl;
system("pause");
return 0;
}
Compiling it and running it on Visual Studio itself runs just fine. However on the Cygwin bash, after inserting the following command:
$ g++ -Wall -g -o Test.exe main.cpp
When I run the Test.exe
, the console closes almost immediately and under the Hello World line, it says something like:
sh:pause: command not found.
It's bit hard to see since it closes so fast. Anybody knows why?
Not sure if this is related, but when the
#include <cstdlib>
is excluded, the error on the cygwin bash will be:
$ g++ -Wall -g -o Test.exe main.cpp
main.cpp: In function `int main()':
main.cpp:10:18: error: `system' was not declared in this scope
system("pause");
^
Is this the right way to solve the error? Documentation and tutorials on Cygwin is difficult to find, so I am not entirely sure if #include <cstdlib>
is correct too.
If you really need it to work in both environments call system("cmd /C pause")
instead of system("pause")
. This will force the Windows shell to start and then invoke it's pause command.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments