Sankha Subhra Som writes:
I have this peculiar problem with g++ under linux. This is a small piece of code that i wrote #include<iostream.h> main() { cout << "blahblah"; }
When i try to compile it, i get the following warning
[snip]
IMHO the o/p is unrelated to g++.
from the stdout man pages stdout is line buffered when associated with a terminal, stderr is unbuffered, stdin is generally line buffered. Modify your program as follows and it will work fine. It will give the same warning as above.
<code> #include<iostream.h> main() { cout << "blahblah" << endl ; ^^^^^^^^^ } </code>
Also try out the following two programs which illustrate the point the buffering funda.
<code> #include <stdio.h> main() { printf("hello world"); } </code>
On redirecting to a file the program is working fine(you see the o/p). Files are full buffered. file buffers are flushed when the program exits, the same is not true of stdout. However fflush can be used to flush the buffers. Also sometimes sync() can do the trick. how ever the program run the command line does not print anything. Now try this modified program.
<code> #include <stdio.h> main() { printf("hello world\n"); ^^ } </code>
Note the \n which flushes the line buffer.
When i try to run the executable the shell does a silent return, without printing the blahblah as it is supposed to. I redirected the output to a file, and it contained blahblah. I dont think the problem is with g++, but i cant exactly put my finger on it.
I hope that answers your question.
Vinayak Hegde APGDST Student NCST-JUHU