GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 08-Jul-2005, 07:48
strangr314 strangr314 is offline
New Member
 
Join Date: Jul 2005
Posts: 4
strangr314 is on a distinguished road

Program output in wrong order


When i use a combination of cout and printf statements, the program does not seem to read them from top to bottom as it moves down the program. It seems to see and evaluate the printf's first. Anyone know why this happens? The output i get when i run the following code is:

Line2
Line4
Line1
Line3

I thought i should be getting :
Line1
Line2
Line3
Line4


CPP / C++ / C Code:
	
		#include <stdio.h>
		#include <stdlib.h>
		#include <iostream.h>

	void main()
{
		cout << "\nLine1";
		printf("\nLine2");
		cout << "\nLine3";
		printf("\nLine4");
	exit(0);

} 
  #2  
Old 08-Jul-2005, 08:11
Dave Sinkula Dave Sinkula is offline
Member
 
Join Date: Apr 2005
Posts: 199
Dave Sinkula will become famous soon enough
In general, I don't think it's a good idea to mix the two, but here's something to try.
  #3  
Old 08-Jul-2005, 08:16
strangr314 strangr314 is offline
New Member
 
Join Date: Jul 2005
Posts: 4
strangr314 is on a distinguished road
Thanks! Putting in the line of code suggested on that page solved the problem. I'm only using the cout to help me make sure the program is working properly so i shouldn't need it in the end.

Thanks Again!
  #4  
Old 08-Jul-2005, 12:42
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,234
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by strangr314
Thanks! Putting in the line of code suggested on that page solved the problem. I'm only using the cout to help me make sure the program is working properly so i shouldn't need it in the end.

Thanks Again!

You'd be better off changing the cout to printf()/puts() even in the beginning. No sense hitting your head against the wall because your debugging is throwing off your code/data. Stick with one or the other but never mix two differen output styles in a program. As you've seen, headache-city!
__________________

Cow: You're a lawyer too?
Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase!
 
 

Recent GIDBlogFirst week of IA training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[TUTORIAL] Calling an external program in C (Linux) dsmith C Programming Language 4 22-Apr-2005 13:30
What's wrong with my program? agentxx04 C Programming Language 2 23-Nov-2004 20:48
Something's wrong w/my program. agentxx04 C Programming Language 1 07-Nov-2004 10:03
Re: Pausing a Program WaltP C Programming Language 3 28-Jul-2004 01:08
using vector or array oshiotse CPP / C++ Forum 4 16-Apr-2004 10:59

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:34.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.