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 > simple c++ prog, in Project Builder

simple c++ prog, in Project Builder
Thread Tools
Registered User
Join Date: Jun 2001
Location: Texas
Status: Offline
Reply With Quote
Sep 1, 2001, 12:45 AM
 
Hi, I'm trying to compile a simple c++ program that I need to turn in for my class using Project Builder (in OSX). I have the program working, and it compiles and runs on my PC, but I would like to be able to compile on the go using my iBook. Keep in mind this is an unbelievably no brainer program. My question is this. ... when it runs, it just sits there waiting for input, without the user prompt I have programmed in. (just a cout statement). My code is as follows:

// get input from user
cout << "Enter three integer values: ";
cin >> num1 >> num2 >> num3;

The problem is, instead of following that first line... it just sits there on a blank screen awaiting user input. and after you input the three numbers, it will display that first line. (also, the variables are all declared, so that' part is fine)

Does anyone know why it doesn't display the prompt? I've tried this using the c++ command in the command prompt, and also using project builder, and both do the same thing. But when I compiled and ran this program on my PC using Visual Studio, and also Code Warrior... it worked as it should. So I'm thinking its something with OSX. any ideas?
     
Mac Enthusiast
Join Date: Dec 2000
Status: Offline
Reply With Quote
Sep 1, 2001, 02:55 AM
 
Sorry, cannot offer solution, but I also have that problem. I think I may have a solution but haven't tested it yet. When you create a new CPP project in PB, it starts up with:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier><font color = green>int</font> main(<font color = green>int</font> , <font color = green>char</font> etc) </font>[/code] rather than just <BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier> <font color = green>int</font> main()</font>[/code]

Try inserting your code into the default startup code.


My name's ...uh... it's a bummer man.
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Sep 1, 2001, 05:45 AM
 
int main(void) is a perfectly valid main function. int main (int argc, char *argv[]) is the other perfectly valid main function. The latter allows you to parse arguments passed to your program.

There is a but in OS X's C++ libraries.

Posted by Doug Landauer &lt;landauer@apple.com&gt; to cocoa-dev@lists.apple.com on Wed Aug 29, 2001 08:10:52 pm Europe/London
<STRONG>On Wednesday, August 29, 2001, at 10:29 AM, Scott Tooker wrote:
&gt;The address you want is projectbuilder-users@lists.apple.com.
&gt;
&gt;I believe that you are running into a bug in the STL libraries on 10.0.x.

Actually, it's in the Standard C++ Library, not in the STL part of that.

&gt;I believe this should be fixed in the next release, but others on the Project Builder list would know the specifics.

The Radar numbers for this bug are 2674713 and the related 2557789.
And yes, the fix will be in the next release.

There are several possible workarounds:

- de-synchronize cout from stdout. I.e., once, somewhere near
the start of your program, call:

cout.sync_with_stdio(false);

OR

- make stdout unbuffered. Once, near the start of your program:

setbuf( stdout, 0 );

OR, if you'd rather keep stdout buffered most of the time,
you'll have to flush it explicitly each time you send out
a non-line and want it to show up before you write the newline:

- explicitly flush stdout:

fflush(stdout);</STRONG>
     
Forum Regular
Join Date: Aug 2001
Location: Vienna, Austria
Status: Offline
Reply With Quote
Sep 2, 2001, 05:53 PM
 
There's a known bug in stdc++ in 10.0.x, which causes this behavior.

The workaround is to call fflush(stdout); between the two lines.
     
Registered User
Join Date: Jun 2001
Location: Texas
Status: Offline
Reply With Quote
Sep 3, 2001, 10:24 AM
 
thanks for the help. I found a temporary workaround for my programming needs. the guys above at work said I could just telnet into the work servers and use gpp to compile. Linux is so nice
     
   
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 02:53 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