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 > How do I run command line C++ apps?

How do I run command line C++ apps?
Thread Tools
Fresh-Faced Recruit
Join Date: May 2001
Location: Burlington, IA
Status: Offline
Reply With Quote
May 23, 2001, 05:04 PM
 
I need to know how to run C++ apps through the command line. I write them in pico and compile them using the c++ command but I cannot run them. On my linux server, I run C++ apps by typing ./a.out programname but this gives me an error. I write mostly mathematical apps, like adding all the numbers from 0 to 100 or calculating the position of planets. I would like some help so I can move from my i586 Linux box to OS X on a 500 G3.

------------------
There is no death, there is life. There is no ignorance, there is the Mac.
There is no death, there is life. There is no ignorance, there is the Mac.
     
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
May 23, 2001, 05:11 PM
 
What's the error?

./a.out works just fine for me.
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Fresh-Faced Recruit
Join Date: May 2001
Location: Burlington, IA
Status: Offline
Reply With Quote
May 23, 2001, 05:29 PM
 
Either it gives me a command not found error or it does nothing. I am including a little C++ program I wrote. Maybe I don't have the right headers or something.
#include<iostream.h>
#include<math.h>

main()
{

float i, x, sum;
sum = 0;
cout << "Enter x: ";
cin >> x;
cout << endl;
for ( i=1 ; i<= x ; i++ )
{
sum = sum + i;
}

cout << "The sum of the numbers between 1 and "<<x<<" is: ";
cout << sum;
cout << endl;
return (0);
}
There is no death, there is life. There is no ignorance, there is the Mac.
     
Dedicated MacNNer
Join Date: Sep 2000
Location: Brisbane, Queensland, Australia
Status: Offline
Reply With Quote
May 23, 2001, 05:37 PM
 
#include <iostream> (make sure it has a space).

Originally posted by lonejedi:
Either it gives me a command not found error or it does nothing. I am including a little C++ program I wrote. Maybe I don't have the right headers or something.
#include<iostream.h>
#include<math.h>

main()
{

float i, x, sum;
sum = 0;
cout << "Enter x: ";
cin >> x;
cout << endl;
for ( i=1 ; i<= x ; i++ )
{
sum = sum + i;
}

cout << "The sum of the numbers between 1 and "<<x<<" is: ";
cout << sum;
cout << endl;
return (0);
}
     
Fresh-Faced Recruit
Join Date: May 2001
Location: Burlington, IA
Status: Offline
Reply With Quote
May 23, 2001, 05:46 PM
 
Nope, still doesn't work. Now it just sits there like it activated the application but won't give the the user prompts.

------------------
There is no death, there is life. There is no ignorance, there is the Mac.
There is no death, there is life. There is no ignorance, there is the Mac.
     
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
May 23, 2001, 06:15 PM
 
Aha! The main problem: You need to flush your iostream.

Put a \n at the end of each cout. That'll work.
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Fresh-Faced Recruit
Join Date: May 2001
Location: Burlington, IA
Status: Offline
Reply With Quote
May 23, 2001, 06:28 PM
 
How do you mean? I tried putting \n in my code like I was taught but I get stray '\' in program errors when I compile. If you could give me a small C++ program that you know works I think it would help.

------------------
There is no death, there is life. There is no ignorance, there is the Mac.
There is no death, there is life. There is no ignorance, there is the Mac.
     
   
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 03:14 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