Cannot execute compiled exe file with C ++

I am having trouble running C ++ code. I wrote the base program "Hello World" and compiled it using the g ++ make . Here is my code:

 #include <iostream> using namespace std; int main() { cout << "Hello World" << endl; return 0; } 

I'm on Windows 10, using Emacs to edit code, and CygWin to compile. I saved this file as hello.cpp. Then I went to the directory in CygWin. Then I ran the make hello command. This created hello.exe. Then I tried to execute the file using ./hello.exe . I also tried ./hello , which also did not work. When I type one of these commands and press Enter, it's just on the next line, doing nothing. I can enter this empty string, but it won’t do anything. Does anyone know how to properly execute my code. Thanks.

EDIT: I tried running this on cpp.sh, the C ++ online compiler, and it worked fine.

+5
source share
2 answers

Your program probably works, but the console window closes before you can see anything.

Try adding input at the end of the program so that it waits.

those.

 int a; cin >> a; 
+2
source

Your code is most likely executed, but does not output anything. This is because he is failing. Try checking return value after start with echo $? . If it is not 0 , then it crashed. Also run it in gdb and see if it works. The reason this fails, most likely the windows / cygwin collision, is not your code.

0
source

Source: https://habr.com/ru/post/1239945/


All Articles