The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Development Releases: Linux Mint 4.0 Beta "Fluxbox", 4.0 Alpha "Debian" iBot UNIX and Linux RSS News 0 01-04-2008 12:00 PM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-19-2007 10:52 PM
Unix "at" / "Cron" Command New Problem...Need help Mohanraj UNIX for Dummies Questions & Answers 3 01-26-2006 05:08 PM
No utpmx entry: you must exec "login" from lowest level "shell" peterpan UNIX for Dummies Questions & Answers 0 01-18-2006 01:15 AM
Why ""No mountable file system" endeavour1985 High Level Programming 0 03-02-2005 06:01 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 10-03-2001
Registered User
 

Join Date: Oct 2001
Location: Columbus, OH
Posts: 6
system("PAUSE") Problem.....

Ok, here's the situation....I have this code...

#include <iostream.h>
#include <stdlib.h>

int main()
{
cout << "\nBlah, and Blah\n\n";

system("PAUSE");

return 0;
}

Now, "system("PAUSE")" gets executed before "cout" does, and I have absolutely no idea why, so when I type this in instead...

#include <stdio.h>
#include <stdlib.h>

int main()
{
printf ("\nBlah, and Blah\n\n");

system("PAUSE");

return 0;

}

...it works just fine....it's like printf has precidence over cout, which I need to fix. So, does anyone know another way for a PAUSE using cout, and does anyone have anymore information on why this situation occurs? Thanks!

Mike
__________________
I like to play Quake
Reply With Quote
Forum Sponsor
  #2  
Old 10-03-2001
rwb1959's Avatar
Registered User
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
Any output to stdout/cout is buffered (unless you have set the
proper ioctl's for unbuffered output) so there is no
guarantee that you will see the output when the
cout << ... OR printf() is executed. If you want to guarantee
that the output goes to the screen prior to executing the
next statement, in C++ you can simply add " << endl" or
in C you can call fflush(stdout) prior to calling "system()".

Actually, the fact the printf() works is hit or miss.
It may or may not work.
Reply With Quote
  #3  
Old 10-03-2001
Registered User
 

Join Date: Oct 2001
Location: Columbus, OH
Posts: 6
Ah...

This answered my question _perfectly_, :) thank you very much for your help, i appreciate it

Mike
__________________
I like to play Quake
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:18 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0