简体   繁体   中英

std::endl results in crash

During the development of a simple example (I haven't programmed C++ for some time) I encountered a weird behaviour. Following hello world program crashes under Windows (Mingw):

#include <iostream>

int main () {

    for (int idx = 0; idx < 5; idx++) {
        std::cout << "Hello World" << std::endl;
    }

    return 0;
}

If I remove std::endl the program does not crash though.

I use following commands to compile and execute the example, with Mingw32 (g++ 4.8.1) on a 64bit system and OS:

g++ example.cpp -o example.exe
example.exe

The error message is:

example.exe does not work any longer...

Is this a known issue or an obvious mistake of mine?

<< endl is a manipulation essentially a function. your output cant be flushed which is causing problems.

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