简体   繁体   中英

C++ run error when using endl

I've recently started to learn C++ and I'm trying to compile and run a very simple program.

#include <iostream>

using namespace std;

int main() {

    cout << "Hello World!" << endl;
    cout << "Hello Again!";

    return 0;
}

The program itself compiles as it should without any errors, however, when the program runs, it seems to stop after cout << "Hello World!" << endl; cout << "Hello World!" << endl; . I find this very strange, as my friend is sitting right beside me, doing the exact same thing and it works for him. The same thing happens when I try to use the sizeof(); ; it does not return any value, however, when my friend does this, it works.

When I ran it in NetBeans, it first generated the error

RUN FAILED (exit value 255, total time: 2s)

And another time I ran it, it generated the same error, but with a different exit value. Although it is now back to 255.

When running debugger in NetBeans it produces

SIGILL (Illegal instruction)

a few times before it stops working.

I have installed the MinGW compiler at the default directory (C:\\MinGW), and this is the compiler that NetBeans and any other program is using. I have also added the path to the System Environment Variables at the end of the "Path" variable:

;C:\\MinGW\\bin;C:\\MinGW\\msys\\1.0\\bin

Trying to run and compile the same code in Atom results in

Hello World!Press any key to continue . . .

I have tried reinstalling the compiler, and restarted my computer. None of which seems to work. I've also tried \\n , which works. My question is, is there anything wrong with my compiler or computer, or am I missing something obvious? And is it possible to fix this?

(Sorry if this is a duplicate, I've searched for a few hours, not able to find anything useful)

I found the culprit! In my System Environment Variables, C:\\MingGW\\bin and C:\\MingGW\\MSYS\\1.0\\bin was at the bottom of the list. This meant that it was below C:\\Program Files (x86)\\GNU\\GnuPG\\pub (Which I think, if I'm not mistaken is another compiler).

Although all paths in NetBeans were correct, it seems like the system didn't like it when another compiler was listed above MinGW.

I solved the problem by moving the paths for MinGW up, above the GNU.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM