loop issue

Mar 22, 2016 at 4:43pm
When I run this in my Eclipse IDE it goes into an infinite loop printing nothing. If I run it in c++ shell on line, it performs what it is directed to do (output infinite 'jj's. Have missed something simple here, or am I out of for while loops?

shell:http://cpp.sh/
1
2
3
4
5
6
7
8
9
10
11
#include<iostream>
int main()  
{	bool yes_loop = 1;

		while (yes_loop == 1)
		{
			std::cout<<"jj";
		}

	return 0;
}
Last edited on Mar 22, 2016 at 4:45pm
Mar 22, 2016 at 5:06pm
The execution environment may buffer output per line, so it's possible for nothing to get printed until the next newline.
You can request the buffers to flush with << std::flush
Mar 22, 2016 at 7:30pm
std flush didn't work:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include<iostream>

int main()
{
	int yes_loop = 1;

		while (yes_loop == 1)
		{
			std::cout<<"jj"<<std::flush;
		}

	return 0;
}


However, I read ths line:
Also note that inserting std::endl will also flush after writing a newline.


By ending an <<endl;

This works! But I can't use the loop while without endl. Strange.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include<iostream>

int main()
{
	int yes_loop = 1;

		while (yes_loop == 1)
		{
			std::cout<<"jj"<<std::endl;
		}

	return 0;
}



output:
jj
jj
jj
jj
jj
jj
...as you might imagine
Last edited on Mar 22, 2016 at 7:31pm
Mar 23, 2016 at 5:04am
It's an old bug (status 'WONTFIX' for nine years and counting) in eclipse on windows.
std::cout << "jj" << std::flush ; won't flush without a new line ( std::cout << "jj\n" << std::flush ; )

Eclipse console does not show output on Windows

In Eclipse CDT on Windows, standard output of the program being run or debugged is fully buffered, because it is not connected to a Windows console, but to a pipe.
http://wiki.eclipse.org/CDT/User/FAQ#Eclipse_console_does_not_show_output_on_Windows
Topic archived. No new replies allowed.