C++ and Xcode

Discussion in 'Mac Programming' started by Epprecht, Nov 6, 2005.

  1. macrumors newbie

    Joined:
    Aug 13, 2005
    #1
    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.
     
  2. macrumors 6502a

    Whyren

    Joined:
    Jun 3, 2004
    Location:
    east of the West and west of the East
    #2
    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.
     
  3. macrumors 68000

    Earendil

    Joined:
    Oct 27, 2003
    Location:
    Washington
    #3
    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
     
  4. Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #4
    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.
     
  5. thread starter macrumors newbie

    Joined:
    Aug 13, 2005
    #5
    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.
     
  6. thread starter macrumors newbie

    Joined:
    Aug 13, 2005
    #6
  7. macrumors member

    Joined:
    Nov 13, 2005
    #7
    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.
     
  8. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #8
    Try cleaning the project. Then quit Xcode, and recompile the project. Should work (I got this exact same error a few days ago also).
     
  9. macrumors 6502

    Joined:
    Nov 10, 2005
    Location:
    New South Wales, Australia
    #9
    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?
     
  10. macrumors newbie

    Joined:
    Nov 7, 2005
    Location:
    Voronezh, Russia
    #10
    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 << ...
    Code:
    cout << "Enter the length of the block (in meters)..."[B] << endl[/B];
    May be it is a flushing problem of the output stream...
     
  11. macrumors newbie

    Joined:
    Nov 14, 2005
    #11
    Very Same Problem

    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;
    }
     
  12. macrumors 6502a

    Laser47

    Joined:
    Jan 8, 2004
    Location:
    Maryland
    #12
    I pasted it in my xcode and it worked.
     
  13. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #13
    I'm pretty sure it's an Xcode problem, not a code issue. Have you tried cleaning the project, and/or relaunching Xcode?
     
  14. macrumors 6502a

    csubear

    Joined:
    Aug 22, 2003
    #14
    Also try running your binary from the terminal. Looks like xcode screwed up its i/o redirect.
     
  15. thread starter macrumors newbie

    Joined:
    Aug 13, 2005
    #15
    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
     
  16. macrumors 6502a

    Whyren

    Joined:
    Jun 3, 2004
    Location:
    east of the West and west of the East
    #16
    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.
     
  17. macrumors newbie

    Joined:
    Nov 14, 2005
    #17
    Found something else

    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)
     
  18. macrumors member

    Joined:
    Mar 23, 2004
    Location:
    MN
    #18
    Did you try selecting "Standard I/O Log" from the "Debug" Menu?
     
  19. thread starter macrumors newbie

    Joined:
    Aug 13, 2005
    #19
    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
     
  20. macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #20
    Seeing this first time, it won't work properly because system("PAUSE"); does not exist on Macs.
     

Share This Page