Xcode help

Discussion in 'Mac Programming' started by ktalebian, Dec 25, 2007.

  1. ktalebian macrumors regular

    Dec 25, 2007
    I have installed Xcode 3 on my Mac OS X 10.5.1, and i want to use it to program C++. But the problem is that I really don't know how!
    I went to start a new project, and selected Carbon C++ Standard.
    Then I added a cpp file to it, and used the very simple code:

    #include <iostream>

    int main(void)
    cout << "Hello World!";
    return 0;

    but it did not compile! Why?
  2. Cromulent macrumors 603


    Oct 2, 2006
    The Land of Hope and Glory
    Choose a C++ Tool project from the Command Line Utility section in the new project menu.
  3. Traith85 macrumors newbie

    Dec 29, 2007
    Same Problem, but with C instead of C++

    I'm also in almost the same situation - using Xcode version 3.0 on OS X 10.5.1, but am trying to compile the "hello world!" example code by starting a new project and choosing "external build system" under the Dynamic Library project category. The code I'm using is:

    #include <stdio.h>

    int main (int argc, const char * argv[])
    printf("Hello, World!\n");
    return 0;

    My problem is that it debugs and runs without error, but there is no output on the screen. The only way that I can get a result is by accessing the Console under the "Run" menu, which does display the output. I'm also completely new to programming and trying to get a feel for the tools - is this normal or should there be an output screen that pops up once I compile? Any advice?
  4. lancestraz macrumors 6502a


    Nov 27, 2005
    This is normal. I just keep the console visible at all times.
  5. gnasher729 macrumors P6


    Nov 25, 2005
    Because you got something wrong.

    Now if you want us to tell you what you got wrong, what about telling us whether the compiler gave you any error messages, and if it did, which ones it gave?
  6. Traith85 macrumors newbie

    Dec 29, 2007
    lancestraz - thanks for the clarification - appreciate it.
  7. sord macrumors 6502

    Jun 16, 2004
    Looking at your code, you have 1 problem, with 3 ways to fix
    Problem: cout is in the std namespace, which you haven't referenced.
    • Add "using namespace std;" under your #include (worst option)
    • Add "using std::cout;" under your #include (best option)
    • Change your cout to std::cout (only decent if you are only going to use it once or twice)

    Also its better practice to have your main be "int main(int argc, char *argv[])" instead of "int main(void)"

Share This Page