PDA

View Full Version : C++ and Xcode




Epprecht
Nov 6, 2005, 11:58 PM
Hi, I'm a student learning C++, new to macs and xcode. Here's my situation: I begin a new project, choose C++ tool from the Command Line Utility Group, then write the source code. I click the build and go button and it compiles fine but will not execute. I keep getting [Session started at 2005-11-07 00:42:23 -500.] or http://i3.photobucket.com/albums/y71/swissgnr/Picture1.png and thats it. A friend of mine who uses Xcode and does C++ cannot figure out why I keep getting this. I'm not sure if it is something I'm doing wrong or what. If anyone could help it would be much appreciated.



Whyren
Nov 6, 2005, 11:59 PM
Hi, I'm a student learning C++, new to macs and xcode. Here's my situation: I begin a new project, choose C++ tool from the Command Line Utility Group, then write the source code. I click the build and go button and it compiles fine but will not execute. I keep getting [Session started at 2005-11-07 00:42:23 -500.] or http://i3.photobucket.com/albums/y71/swissgnr/Picture1.png and thats it. A friend of mine who uses Xcode and does C++ cannot figure out why I keep getting this. I'm not sure if it is something I'm doing wrong or what. If anyone could help it would be much appreciated.
Welcome to MacRumors Forums!

What is your code supposed to be doing? It appears as though it is running, but there are no I/O prompts.

Earendil
Nov 7, 2005, 01:36 AM
Post a code and I'll give a looksee. No Promises though, I'm no expert on C++ under OSX, but I want to be :D

~Earendil

caveman_uk
Nov 7, 2005, 02:58 AM
That the 'Run' button is visible suggests your program isn't actually running in that screenshot - otherwise the button would say 'Terminate' and be a red stop sign.

Epprecht
Nov 7, 2005, 08:41 AM
Here is a screenshot of my source code; http://i3.photobucket.com/albums/y71/swissgnr/source.png This program is one that I had earlier this year and completed. I've used two C++ compilers before called Cygwin and Dev++, both compile and execute the program fine. So, I'm not sure if the problem is with my code or I'm not doing something right in Xcode.

Epprecht
Nov 14, 2005, 12:39 AM
I'm not sure if anyone is looking at this anymore but I downloaded Xcode 2.2 and tried the program again and got this http://i3.photobucket.com/albums/y71/swissgnr/xcode.png, which was different from before. Any suggestions on what to do, thanks.

InfiniteLoop
Nov 14, 2005, 12:45 AM
I'm not sure if anyone is looking at this anymore but I downloaded Xcode 2.2 and tried the program again and got this http://i3.photobucket.com/albums/y71/swissgnr/xcode.png, which was different from before. Any suggestions on what to do, thanks.

I am new to macs and have no idea about Xcode, but I think it means it could not find the executable you think you've just compiled/built.

kainjow
Nov 14, 2005, 01:52 AM
Try cleaning the project. Then quit Xcode, and recompile the project. Should work (I got this exact same error a few days ago also).

hopejr
Nov 14, 2005, 05:58 AM
I've been using Xcode for ages for Cocoa development and didn't know you could do what you're trying to attempt. I usually use the terminal ;)

Well, I just tried your code, and it works for me (using Xcode). Do you have problems with other projects?

Selivanov
Nov 14, 2005, 06:52 AM
I don't knkow - if it is a bug or something else, but... you need to output '\n' at the end of the line.
Try the following code in the first cout << ...
cout << "Enter the length of the block (in meters)..." << endl;
May be it is a flushing problem of the output stream...

I3AnThRaX69
Nov 14, 2005, 10:27 PM
Im having the very same problem with the xcode tools about trying to run the program. It just says "[Session started at 2005-11-14 21:25:27 -0700.]" and nothing happens, i even try to click RUN like thousands of times and it just sits there i tried to use the help file and that didnt help for anything, and I didn't notice anything that helped the other person about his problem. Im just new to programing and dont get anything but here is my .cpp file
//
// Program to convert tempurature from Celsius degree
// units into Fahrenheit degree units:
// Fahrenheit = Celsius * (212 - 32)/100 + 32
//
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
// enter the tempurature in Celsius
int celsius;
cout << "Enter the tempurature in Celsius:";
cin >> celsius;

// calculate conversion factor for Celsius
// to Fahrenheit
int factor;
factor = 212 - 32;

// use conversion factor to convert Celsius
// into Fahrenheit values
int fahrenheit;
fahrenheit = factor * celsius/100 + 32;

// output the results (followed by a NewLine)
cout << "Fahrenheit value is:";
cout << fahrenheit << endl;

// wait until user is ready before terminating program
// to allow the user to see the program results
system("PAUSE");
return 0;
}

Laser47
Nov 14, 2005, 10:39 PM
Im having the very same problem with the xcode tools about trying to run the program. It just says "[Session started at 2005-11-14 21:25:27 -0700.]" and nothing happens, i even try to click RUN like thousands of times and it just sits there i tried to use the help file and that didnt help for anything, and I didn't notice anything that helped the other person about his problem. Im just new to programing and dont get anything but here is my .cpp file
//
// Program to convert tempurature from Celsius degree
// units into Fahrenheit degree units:
// Fahrenheit = Celsius * (212 - 32)/100 + 32
//
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
// enter the tempurature in Celsius
int celsius;
cout << "Enter the tempurature in Celsius:";
cin >> celsius;

// calculate conversion factor for Celsius
// to Fahrenheit
int factor;
factor = 212 - 32;

// use conversion factor to convert Celsius
// into Fahrenheit values
int fahrenheit;
fahrenheit = factor * celsius/100 + 32;

// output the results (followed by a NewLine)
cout << "Fahrenheit value is:";
cout << fahrenheit << endl;

// wait until user is ready before terminating program
// to allow the user to see the program results
system("PAUSE");
return 0;
}
I pasted it in my xcode and it worked.

kainjow
Nov 14, 2005, 10:43 PM
I'm pretty sure it's an Xcode problem, not a code issue. Have you tried cleaning the project, and/or relaunching Xcode?

csubear
Nov 14, 2005, 10:53 PM
I'm pretty sure it's an Xcode problem, not a code issue. Have you tried cleaning the project, and/or relaunching Xcode?

Also try running your binary from the terminal. Looks like xcode screwed up its i/o redirect.

Epprecht
Nov 14, 2005, 11:00 PM
I have tried cleaning the project and reopening it and it didn't work. Maybe I did not install xcode properly or something. Also, how would I try running my binary from the terminal? I'm still not sure how to do many things with xcode. Thanks

Whyren
Nov 14, 2005, 11:37 PM
I may have found your problem. Your project name in the first instance seems to be named "mow.cpp" so your executable ends in ".cpp"; this appears to confuse XCode. I tried naming my project similarly and it produced the problem you're having.
Rename your project w/o ".cpp", build and see if it works.

I3AnThRaX69
Nov 14, 2005, 11:51 PM
I talked to my friend about this and he also said that his xcode just ran it fine and he found me a 3rd party software to compile the c++ code which worked for me perfectly.
http://mac.softpedia.com/progDownload/CPP-Edit-Download-8775.html
(just in case someone else had this problem here is a quick solution)

vasaz
Nov 14, 2005, 11:56 PM
Did you try selecting "Standard I/O Log" from the "Debug" Menu?

Epprecht
Nov 15, 2005, 12:49 AM
Yay! First, thank you Whyren, it did work not including the .cpp to the filename. I was used to adding the .cpp but I'm learning. I3AnThRaX69, thanks for the alternative and thanks to everyone else for the help! This thread was a my first post on MacRumors: Forums after lurking around for quite a while and it's a good place. danke

Soulstorm
Nov 15, 2005, 03:16 AM
Im having the very same problem with the xcode tools about trying to run the program. It just says "[Session started at 2005-11-14 21:25:27 -0700.]" and nothing happens, i even try to click RUN like thousands of times and it just sits there i tried to use the help file and that didnt help for anything, and I didn't notice anything that helped the other person about his problem. Im just new to programing and dont get anything but here is my .cpp file
//
// Program to convert tempurature from Celsius degree
// units into Fahrenheit degree units:
// Fahrenheit = Celsius * (212 - 32)/100 + 32
//
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
// enter the tempurature in Celsius
int celsius;
cout << "Enter the tempurature in Celsius:";
cin >> celsius;

// calculate conversion factor for Celsius
// to Fahrenheit
int factor;
factor = 212 - 32;

// use conversion factor to convert Celsius
// into Fahrenheit values
int fahrenheit;
fahrenheit = factor * celsius/100 + 32;

// output the results (followed by a NewLine)
cout << "Fahrenheit value is:";
cout << fahrenheit << endl;

// wait until user is ready before terminating program
// to allow the user to see the program results
system("PAUSE");
return 0;
}
Seeing this first time, it won't work properly because system("PAUSE"); does not exist on Macs.