I wrote a CPP program on Code::Blocks and compiled it (MinGW). It is a simple application but shows a big problem that I still can't solve.
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "Something here";
return 0;
}
When I try to run this program (on code blocks [F9 - compile and run]) I get this as result: Console
Nothing happens...
If I execute it out from codeblocks, it just opens and disapears. But on the two cases, it is unkillable, I cant kill this proccess. But when I try to restart the computer, I get an error, it says that the program wasn't correctly initialized. I don't know how to debug programs, and I have no idea of how to proceed. Could you help me?
Sorry for any language mistakes, I'm not an english master (yet). Thank you.
Edit:
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "Something here" << std::flush;
return 0;
}
It stills not working. Even with '\n'
or std::endl
.
You didn't std::flush
your output, so the "Something here" is stuck on the internal buffer of std::cout
and is not printed before your program ends.
To fix that, you can (pick one):
std::cout << "Something here" << std::endl;
std::cout << "Something here\n";
std::cout << "Something here" << std::flush;
Thanks to Bo Persson (that commented at my post), I fixed it by turning off my antivirus (Avast). Thank you!
Edit:
std::cout << "Something here";
(without std::flush
) works as well after disabling Avast.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With