need help with strange cout behaviour

Hi guys, i was writing a c++ program to call another program and i ran into this problem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
        volatile int j=1;
        for(i;i<argc;i++)
	{
		std::cout << j<<". "<<"Running "<<argv[i] << "  ";      // Mark1
		std::string exec=/*my statement for system() here*/;
		system(exec.c_str());
		std::ifstream out("out");
		out.seekg(-15,out.end);
		char ok[3]={0,0,0};
		out.read(ok,2);
		if(std::string(ok) == std::string("OK"))
	  	{
			std::cout << "......" << ok << std::endl;       // Mark2
		}
		else
		{
			std::cout << "......" << ok<<"  fail " << std::endl;
		}
		j++;
				
	}


In this program the system function calls an executable that takes at least 20 sec per argv but i found that the cout in line with comments Mark1 and Mark2 get print at the same time at the end of the loop... cant figure out why... i even introduced a volatile variable thinking it would fix it... any idea why the program is behaving this way..
Last edited on
Last edited on
Thanks for the answer using std::flush worked.

std::ifstream out
o_O


i used >out 2>&1 in the system function so its out there but i read it here so its std::ifstream out here ;)
Topic archived. No new replies allowed.