0

I was refreshing myself with C++ today, and I wrote a hello world .cpp program using notepad++, then compiled it using g++. The executable, when called from the windows command prompt, doesn't run, but is still open by the command prompt and I don't know why this is happening. I also tried using gcc to compile a C program and it worked fine. I installed both gcc and g++ using MinGW on Windows 8. I've checked the path variables, I've reinstalled g++ using MinGW, and I've restarted the computer all to no avail. The code is shown below. Thanks for all your help!

#include <iostream>
int main(){

  std::cout<<"Hello World";

  return 0;

}

The command I used to compile the .exe is:

g++ -o my_output_name my_input_file.cpp

When "my_output_name" is typed into the command prompt, the little blinky cursor jumps a line, like it's going to write out "Hello World!" but never does and just hangs up there.

Cate
  • 1,227
  • 2
  • 9
  • 7
  • Is it your source file name `my_input_file.pp` or `my_input_file.cpp`? – Steephen Dec 17 '15 at 02:27
  • You're right, That was just a typo on the stack exchange posting. Thanks, I edited it. – Cate Dec 17 '15 at 02:30
  • what happens if you change it to `std::cout << "Hello World" << std::endl;` ? – Olipro Dec 17 '15 at 02:34
  • I tried that too, `std::cout << "Hello World!" << std::endl; ` was the first thing I tried. It worked as well as the above example. It didn't work at all. – Cate Dec 17 '15 at 02:35
  • I've also tried `using namespace std;` too so don't ask, haha. – Cate Dec 17 '15 at 02:36
  • 4
    Flushing shouldn't make a difference, the standard streams flush when they're destroyed at the end of the program. Stupid question but are you absolutely sure you are running the executable you just compiled, and not something from an earlier test? – user657267 Dec 17 '15 at 02:37
  • That might be it, because there's this other application that says it's open in the command prompt but I have no idea how to close it. I don't know what process to close in the task manager. Also since it's open I can't delete it. I just checked and it shouldn't be running, but when I tried to delete it it said it was open by another program. Do you have any idea how to delete it or close it? It's called "cpp_review.exe". – Cate Dec 17 '15 at 02:41
  • I've tried "CTRL + C" And that didn't work. I've been able to open new instances of the command prompt without problems. – Cate Dec 17 '15 at 02:42
  • @Cate Try this: `g++ my_input_file.cpp` followed by `a.exe`. – user657267 Dec 17 '15 at 02:45
  • @user657267 It just hangs up again. When I press "Enter" to execute "a.exe" the cursor jumps a line and just sits there and blinks – Cate Dec 17 '15 at 02:50
  • @Cate Stupid question number 2: are you sure the content of `my_input_file.cpp` is exactly the same as what you've posted above? – user657267 Dec 17 '15 at 02:57
  • @user657267 Yes, I cut and pasted that information. – Cate Dec 17 '15 at 02:59
  • 3
    @Cate: Do you use Avast antivirus? – Blastfurnace Dec 17 '15 at 02:59
  • @Blastfurnace I do use Avast. Why would that make a difference? – Cate Dec 17 '15 at 03:00
  • 1
    @Cate: I guess something recently changed in Avast's heuristics or virus signatures triggering all these false positives. If you don't mind, I'll flag it as a duplicate. You can upvote the answer over there if you insist. Glad to help. – Blastfurnace Dec 17 '15 at 03:14

0 Answers0