at some time, cout stops printing in the console

Pages: 12
Hi all,

Everything is in the title. I barely can paste code here since the project is big. It has happened after some modifications in my code but I cannot figure out what changes could lead to that.

Does anyone know some reason cout can break like that ?
Last edited on
Are you using \n instead of endl?
798
799
std::cout << "Hello, World!\n"; //not ok
std::cout << "Hello, World!" << std::endl; //ok 
Sometimes, but always between a cout << and a << endl;

Anyway, even if I might have forgotten some, at least at the next endl, everything should be flushed. Right ?
Last edited on
Yes, endl should flush.
In my case, nothing more is printed ! Is there a mean I could have broken cout at some point ? Though I really cannot figure out what on the heal I could have done bad. cout is simple, isn't it ?
Last edited on
What do you mean "cout is simple"? Simple in what way?

Here's a more important question: how do you know the program keeps going but just doesn't output? Is there some other indication that it has progressed past the point where it stopped printing?
What do you mean "cout is simple"? Simple in what way?
I mean in term of usage.

The program otherwise ends correctly since :
1) I have several output files which are correctly filled.
2) It is a console only application and no exception is displayed.
3) I receive the prompt back normally.

I have just checked all my cout. I have either of these two forms :

cout << "x = " << variableX << ", y = " << variableY << endl;

1
2
3
cout << "table t = ";
for (int i = 0; i < 10; i++) cout << t[i] << " ";
cout << endl;


I have just tried cerr and it outputs on the console. If I don't mistaken, it is normal.
cout, cerr, and clog are all usually mapped to the same output stream on Windows. Exceptions would end your program, not get displayed. (they might get a fancy error dialog if you run in debug mode, or a crash report dialog)

What do you mean by point 3?
What do you mean by point 3?

I run my application from the command line in a shell (under Linux). When the program exits, the prompt ($) is back and the command line is available for new commands.
You might have gotten an error. Why don't you just post your code? If table t only has 9 elements, then your program should terminate because of out of bounds. Though I doubt this is the case. Just post all of your code and someone should be able to help you from the git go rather than just guess around.
If table t only has 9 elements
No, this was just a simplified example of my cout use cases.

Why don't you just post your code?
thousands of lines ?
Besides, I am not authorised to post this code. I must isolate the problem, suppress sensitive information, and so on. For most problems, it is easy, but here, it is not. But I agree it is the only reasonable way. So I will do it. But it will takes me some time.
Last edited on
You have thousands of lines of code, and yet your problem is something as simple as this? I don't believe you, to be honest. But, if each of your lines has a format EXACTLY like the ones you showed, then you have no problem.

(Which means somewhere in your code, there is a line with a format that isn't like the ones you gave us. And to be honest, if you are using an ide, it should tell you exactly approximately (if its a syntax error) which line is causing the problem.)


Edit: My mistake about that. I forgot that everyone else is using outdated IDEs. If only I could give everyone my Magical one.
Last edited on
OH Lol, I didn't read that last line. If you can't post the code, then DON'T do it.

Also. To give another quick answer like the ones above, if any of your lines have '\0' a null character, then that would stop the output also, in most cases.
Last edited on
closed account (zb0S216C)
This may have been suggested already, but have you tried:

1
2
3
std::cout << "My pointless string\n";

std::cout << std::flush;

Note that calls to std::ostream::endl are expensive; excessive use should be avoided.

Wazzak
Last edited on
If you spam COUT, the command line window might just give up on you and lag. I know this happens in Konsole (KDE4, OpenSuse) when I accidentally COUT in an infinite loop.
Which means somewhere in your code, there is a line with a format that isn't like the ones you gave us. And to be honest, if you are using an ide, it should tell you exactly which line is causing the problem.)

I have NO error message at all. Simply, cout first works and somewhere stops working.

if any of your lines have '\0' a null character, then that would stop the output also, in most cases

Thanks for the tip Vlykarye. This is a good idea to look for.

If you spam COUT, the command line window might just give up on you and lag. I know this happens in Konsole (KDE4, OpenSuse) when I accidentally COUT in an infinite loop.

Everything works well except cout.

Here are all the cout in my project : http://pastebin.com/G9h04hXL
Have you bothered checking the state of cout since you've had problems? Does your program continue to run or do you assume it does and that output is the problem?

My guess would be that you've trashed some memory at some point, and your cout problems are the manifestation of that.
Lol... Ok well.. You're code is pointless cus its been trashed with a bunch of
src/Good.cpp:
and other stuff at the beginning of the code.


Edit: My good friend as informed me that this is due to some tool.
Last edited on
Ok. I looked through it. I suggest that you redo all of this code.
Why is down below.

If only 100 lines is output, then what do the other 900 lines do?
Would be helpful since the output lines are using functions and variables in the rest of the 900 lines.

Anyways. The code looks poorly written and hard to read. It would probably suit you and whoever you are working for to rewrite it.
Why? Because it would seem like you are having a problem finding out where the error is (whether it be syntactical or logical). I'm not a genie, but I would guess that you'd have an easier time finding any errors if you're output statements were separated into multiple statements. Which is what I meant by this.


Edit: Thought I would offer some explanation which I thought was obvious.
Last edited on
If only 100 lines is output, then what do the other 900 lines do?


Other stuff? It is not uncommon for useful code to have no output on stdout.


The code looks poorly written and hard to read.


The code looks like it was extracted from files by a tool like grep. Perhaps you'd care to enumerate why you think the code is poorly written?


And to be honest, if you are using an ide, it should tell you exactly which line is causing the problem.


I had no idea there were magic IDEs. Do you have to rub the side before the genie pops out?

@OP: Not enough context to offer a useful opinion.
Pages: 12