Help using XCode to learn C++

Discussion in 'Mac Programming' started by Jalaska13, Mar 21, 2009.

  1. macrumors newbie

    Mar 21, 2009
    Hi guys!
    I've been trying to teach myself C++ from a book that is written for PC users (most are). I simply skipped the steps it says about installing the compiler that comes with the book, and figured i'd use XCode. After all, C++ is the same, no matter the platform. However, i'm having a bit of difficulty. When I try to type in the code examples they give, and then compile and run them, all the "build" and "run" commands are greyed out in the pulldown menus. All i have is a simple C++ file (.cpp). No headers, no make files, nothing. Just that little bit of code. What am I doing wrong?
    here's the code:

    #include <iostream>
    using namespace std;

    int main() {
    cout << "Never fear, C++ is here!";
    return 0;
  2. macrumors 68040


    Jan 10, 2005
    Dallas, TX
    Choose File->New Project
    Under Command Line Utility, choose C++ tool

    Now you can enter your code.

    This will set up the environment for the sort of thing you want to do, so it knows what compiler to use, etc.

  3. thread starter macrumors newbie

    Mar 21, 2009
  4. macrumors newbie

    Oct 3, 2009
    I've just recently started learning C++ on XCode myself and have attempted to make a simple program. My code is:

    #include <iostream>
    #include <string>
    using namespace std ;

    int main (void)
    string name ;

    cout << "Enter you full name. " ;

    cout << "Hello, " << name << endl ;

    return 0 ;

    Before it asks me to enter my name, I see all this stuff in the console window:

    The Debugger has exited with status 0.
    [Session started at 2009-10-19 11:44:11 -0400.]
    GNU gdb 6.3.50-20050815 (Apple version gdb-1346) (Fri Sep 18 20:40:51 UTC 2009)
    Copyright 2004 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB. Type "show warranty" for details.
    This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys001
    Loading program into debugger…
    Program loaded.
    [Switching to process 1213]

    I was wondering if there's a way to get rid of that ^?

    When I enter my name, I get this message:

    MyProgram(1213) malloc: *** error for object 0x1000041e0: pointer being freed was not allocated
    *** set a breakpoint in malloc_error_break to debug
    Program received signal: “SIGABRT”.
    sharedlibrary apply-load-rules all

    Clearly there's an error and I was wondering what is wrong with my code?
  5. macrumors G5


    Nov 25, 2005
    Well, it gives you a bloody big hint what to do if you want to debug your code.
  6. macrumors newbie

    Oct 3, 2009
    considering the fact that i'm new to this and i got this code from a website to test out xcode how am i to know what that jibberish means?
  7. macrumors G5


    Nov 25, 2005
    *** set a breakpoint in malloc_error_break to debug
  8. macrumors newbie

    Oct 3, 2009
    I tried googling '*** set a breakpoint in malloc_error_break to debug' and one result told me to hit 'alt+cmd+B' and then near the blue cube icon to input 'malloc_error_break' i tried that and it didn't work.
  9. macrumors 65816


    Oct 25, 2009
    cin >> name;

    instead of getline stuff you have

    I registered just to reply to this. I am not sure why he is trying to explain much more advanced debugging or whatever rather than just point out the obvious mistake.

    malloc is memory allocation stuff. I am still a student so I cannot really tell you much more.

    Oh and you do not need void inside of int main()

Share This Page