I was doing a simple test. Here is the program test1.cpp
#include <fstream>
#include <iostream>
int main()
{
std::ifstream fin;
fin.open("data.txt");
char tmp[10];
for(int i=0;i<5;i++) {
fin >> tmp;
std::cout << "tmp = " << tmp << " ";
}
std::cout << std::endl;
fin.close();
}
and here is the file data.txt.
1234
5678
9abc
39ab
539b
When I run the program, (I compile it with make CPPFLAGS+=-g test1
) I get
tmp = 1234 tmp = 5678 tmp = 9abc tmp = 39ab tmp = 539b
I can run it with debugger (I use ddd with gdb inside). The result is the same. But when I single step through the for loop, it doesn't print anything. Why is it like that? ADD : from the comment, I recalled there is this buffering and I can use flush to make it print. But I don't understand why it doesn't get printted with single stepping. Somehow the buffer should fill and should be output to monitor. Why? The 'duplicate question' doesn't give me the answer.