By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,194 Members | 817 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

Redirection at the prompt

P: n/a
I had posted this to comp.os.msdos but I did not get an answer.
The program

// Hello.cpp
#include <iostream.h>
#include <stdio.h>
int main ()
{
printf ("Line1 \n");
cout<< "Line2 \n" ;
printf ("Line3 \n");
cout<< "Line4 \n" ;
printf ("Line5 \n");
cout<< "Line6 \n" ;
return 0;
}

when the output was redirected to a file:

c:\tc\bin> hello > a.txt
I could see all the 'cout' lines printed first and then printf lines.
Shouldn't it be in the same order as it appears? Why is it happening?
I am using the Turbo C++ 3.0 compiler.
Nov 14 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Aniruddha wrote:
I had posted this to comp.os.msdos but I did not get an answer.


Still the wrong newsgroup. For C++ programs, try comp.lang.c++.

--
Hallvard
Nov 14 '05 #2

P: n/a
Aniruddha wrote:
I had posted this to comp.os.msdos but I did not get an answer.
The program

// Hello.cpp
#include <iostream.h>
#include <stdio.h>
int main ()
{
printf ("Line1 \n");
cout<< "Line2 \n" ;
printf ("Line3 \n");
cout<< "Line4 \n" ;
printf ("Line5 \n");
cout<< "Line6 \n" ;
return 0;
}

when the output was redirected to a file:

c:\tc\bin> hello > a.txt
I could see all the 'cout' lines printed first and then printf lines.
Shouldn't it be in the same order as it appears? Why is it happening?
I am using the Turbo C++ 3.0 compiler.


This is an issue for the C++ language gurus.
See my reply in news:comp.lang.c++.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Nov 14 '05 #3

P: n/a
an***********@yahoo.co.in (Aniruddha) wrote in message news:<59**************************@posting.google. com>...
I had posted this to comp.os.msdos but I did not get an answer.
The program

// Hello.cpp
#include <iostream.h>
#include <stdio.h>
int main ()
{
printf ("Line1 \n");
cout<< "Line2 \n" ;
printf ("Line3 \n");
cout<< "Line4 \n" ;
printf ("Line5 \n");
cout<< "Line6 \n" ;
return 0;
}

when the output was redirected to a file:

c:\tc\bin> hello > a.txt
I could see all the 'cout' lines printed first and then printf lines.
Shouldn't it be in the same order as it appears? Why is it happening?
I am using the Turbo C++ 3.0 compiler.


Yes this is off topic, but the short answer is the output is buffered.

---
Jared Dykstra
http://www.bork.org/~jared
Nov 14 '05 #4

P: n/a
Jared Dykstra wrote:
an***********@yahoo.co.in (Aniruddha) wrote in message news:<59**************************@posting.google. com>...
I had posted this to comp.os.msdos but I did not get an answer.
The program

// Hello.cpp
#include <iostream.h>
#include <stdio.h>
int main ()
{
printf ("Line1 \n");
cout<< "Line2 \n" ;
printf ("Line3 \n");
cout<< "Line4 \n" ;
printf ("Line5 \n");
cout<< "Line6 \n" ;
return 0;
}

when the output was redirected to a file:

c:\tc\bin> hello > a.txt
I could see all the 'cout' lines printed first and then printf lines.
Shouldn't it be in the same order as it appears? Why is it happening?
I am using the Turbo C++ 3.0 compiler.

Yes this is off topic, but the short answer is the output is buffered.


<off topic>
That's certainly possible, but I don't see how it explains the observed
results. cout is synced with stdio by default. I don't know exactly what
that means, but I would assume that it means output appears in the order
it was sent, regardless of which method was used to send it.

I'm leaning toward a broken C++ implementation, but I'm not sure.
</off topic>

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Nov 14 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.