Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > C++ streams misbehaving

C++ streams misbehaving
Thread Tools
Forum Regular
Join Date: Mar 2001
Location: canada
Status: Offline
Reply With Quote
Jul 10, 2001, 03:36 PM
 
I'm currently learning some C++ while bored at work, sshing into my box at home. Doing some simple stuff doesn't work as I'd expect it to, though, namely with cout and cin.
Consider the following code:

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
#include &lt;iostream&gt;

<font color = green>int</font> main ()
{
<font color = green>int</font> i;
cout &lt;&lt; <font color = red>"Please enter an integer value: "</font>;
cin &gt;&gt; i;
cout &lt;&lt; <font color = red>"The value you entered is "</font> &lt;&lt; i;
cout &lt;&lt; <font color = red>" and its <font color = green>double</font> is "</font> &lt;&lt; i*<font color = blue>2</font> &lt;&lt; <font color = red>".\n"</font>;
<font color = green>return</font> <font color = blue>0</font>;
}
</font>[/code]

When I compile and run this (using /usr/bin/c++) it's like I have the cin before the cout or something:

parsec@localhost ~/learn % a.out
123
Please enter an integer value: The value you entered is 123 and its double is 246.
The exact same code works correctly on my school's solaris box:

@bacon[105]% ./a.out
Please enter an integer value: 123
The value you entered is 123 and its double is 246.
Now, I really don't know any c++ but I know C and Java. I've tried putting flush(cout) and cout.flush() before the cin, to no avail.
Can anyone help me out with how I can get my console i/o working the way it does on my school's machines?
Thanks,

parsec
     
parsec  (op)
Forum Regular
Join Date: Mar 2001
Location: canada
Status: Offline
Reply With Quote
Jul 10, 2001, 07:24 PM
 
OK, so I'm a jackass for not searching before posting but the search wasn't working earlier when I posted.
Anyway, this was discussed ad nauseum at
this thread

And is indeed a bug with apple's implementation.
I guess I'll go see if there is an updated version of cc at apple..

-p
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 11:12 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2