Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't execute compiled C++ exe file

Tags:

c++

g++

cygwin

I am having trouble executing my C++ code. I have written a basic "Hello World" program, and compiled it using the g++ make command. Here is my code:

#include <iostream>

using namespace std; 

int main() {
  cout << "Hello World" << endl;
  return 0;
}

I am on Windows 10, using Emacs for code editing, and CygWin for compilation. I saved this file as hello.cpp. I then navigated to the directory in CygWin. Then I did the command make hello. This created hello.exe. Then, I attempted to execute the file using ./hello.exe. I also tried ./hello which also didn't work. When I type one of these commands and hit Enter, it just on the next line, not doing anything. I can type in this blank line, but it won't do anything. Does anyone know a way to make my code execute properly. Thank you.

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

like image 244
kungfushark Avatar asked Jan 06 '16 00:01

kungfushark


1 Answers

Your program probably is working but the console window is closing before you can see anything.

Try adding an input at the end of the program so it will wait.

I.E.

int a;
cin >> a;
like image 58
Rabbi Shuki Gur Avatar answered Sep 19 '22 14:09

Rabbi Shuki Gur