 |
 |
simple c++ prog, in Project Builder
|
 |
|
 |
|
Registered User
Join Date: Jun 2001
Location: Texas
Status:
Offline
|
|
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
|
|
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
|
|
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 <landauer@apple.com> 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:
>The address you want is projectbuilder-users@lists.apple.com.
>
>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.
>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
|
|
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
|
|
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 
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|