473,324 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Flushing the standard output

7
What is the meaning of "flushing the standard output"?
Aug 6 '09 #1
12 9280
mac11
256 100+
Standard output is buffered, flushing it means to empty the buffer. Your output statements are held in memory until the buffer fills or you flush it, then they are dumped to the console all at once. The reason for this is time savings.

For instance, if you have a program that does
cout << "something";
the "something" will not make it to the screen until somebody flushes the buffer or it fills up, which may be quite some time but usually nobody cares.

The buffer is flushed by using 'flush' or 'endl' in your cout statement.

I'm assuming c++, but if you're referring to c land the same concept holds true except that you printf a newline "\n" to flush the buffer.

Usually, if you want your output to appear immediately (unbuffered) you write to stderr using
cerr << "something";
or
fprintf(stderr,"whatever");
Aug 6 '09 #2
jamik
7
Thanks a lot... Just I understood this one... I asked to write a program using fflush(), I wrote but testing system does not accept. this is taskhttp://day0.ioi2009.org/data/Hill.pdf and here is my solution:

Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<cstdio>
  3. using namespace std;
  4. main (){
  5.      int i,j,n,m,maxi,maxj,max=0,a;
  6.      scanf ("%i %i",&n,&m);
  7.      for (i=1; i<=m; i++){
  8.          for (j=1; j<=n; j++){
  9.              scanf ("%i",&a);
  10.              printf ("0 %i %i\n",j,i);
  11.              fflush(stdout);
  12.              if (a>max){
  13.                         max=a;
  14.                         maxi=i;
  15.                         maxj=j;
  16.                         }
  17.                         if (i==m&&j==n-1){break;}
  18.              }
  19.          }
  20.          printf ("1 %i %i\n",maxj,maxi);
  21.          fflush(stdout);
  22.          getchar();
  23.          getchar();
  24.          return 0;
  25.      }
Aug 6 '09 #3
mac11
256 100+
I looked at your assignment page and it gives an expected input and output sample.

I think you just need to run your program and look closely at your code and follow the path of execution and you should be able to figure out the problem.

Have you tried running your program using the given sample input?
What did it not do correctly?
Aug 6 '09 #4
jamik
7
I cannot understand, while I compile everything is OK, but when I send it to testing system it does not accept... It says that Time Limit Exceeded... Can you just see this testing system... Try to send the solution, maybe you can understand... Please help me in this condition...
Aug 6 '09 #5
Plater
7,872 Expert 4TB
Why are you waiting for two key presses at the end of your program?
Aug 6 '09 #6
jamik
7
It is not changing anything....
Aug 6 '09 #7
mac11
256 100+
I don't want to just tell you what's wrong with your program.

Spend a little time and actually run it on your own computer not send it to some automated tester. Type in the sample input your assignment sheet provides. Hint Hint!! Look at what your program gives for output versus what the sample output should be when you give it the first two lines.

Much of becoming a programmer is learning how to solve faulty logic and dissect problems.
Aug 6 '09 #8
jamik
7
Just that is the question, while I compile it's working correct!!!!
Aug 7 '09 #9
JosAH
11,448 Expert 8TB
@jamik
Please read reply #6 again: your program can't end without human intervention (s/he has to press two character). Possibly the test engine waits ad nauseam and concludes that your program hangs. Take out those two getchar() calls.

kind regards,

Jos
Aug 7 '09 #10
jamik
7
I solved that problem already, now there is a problem, some tests Wrong Answer...
Aug 7 '09 #11
mac11
256 100+
Can you show us the input you give and what output you get - and what output you should get?
Aug 7 '09 #12
jamik
7
I don't know about inputs, becaus I wrote that task cheks the testing system,not me....
Aug 8 '09 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: micha | last post by:
whenever an error occurs after ob_start() the buffer is flushed and the content printed. 1. is that standard behaviour? 2. if yes, how to prevent it? micha p.s. i can't use my own error...
2
by: Graham Ashton | last post by:
Hi. I'm having trouble flushing sys.stdout. I've written a small example to illustrate my problem (see below). In short, I expect it to ping "received hello", sleep for 5 seconds and then print...
6
by: Farshid Lashkari | last post by:
Hi, My application has python embedded into it. I noticed that when I run any python code the output is buffered and doesn't get flushed until my application exits. To fix this I simply flush...
5
by: Christopher Benson-Manica | last post by:
Yes, it's me again, with my dear, dear friends std::streambuf and std::ostream... On the bright side, the code compiles. On the gloomy side, I can't seem to get overflow() or xsputn() called... ...
3
by: Eric | last post by:
Good afternoon, Can anyone help me with flushing the buffer in ASP.NET. I have a set of functions that perform a series of maintainence operations. As these functions are called sequentially,...
2
by: Fabian Steiner | last post by:
Recently I came across a problem which I still can't solve on my own. Consider this small example: import sys import time time.sleep(3) print sys.stdin.flush() input = raw_input('Your...
6
by: tegdim | last post by:
Hello, I'm trying to send a string to a subprocesses' output stream in my java program. I'm writing the data to the stream and then trying to flush the stream. This, however , isn't actually...
5
by: arnuld | last post by:
this is from mentioned section. i did not understand some things here: it means "flushing the buffer" and "writing to output device" are SAME thing, these are just 2 different names for the...
1
by: Ethan Metsger | last post by:
Hi, all. I apologize for what is perhaps a newb question. I'm in the process of transitioning our testing framework from Perl to Python. While that alone probably sets off some red flags,...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.