XCode C++ Question....

Discussion in 'Mac Apps and Mac App Store' started by Weasler, Jul 25, 2007.

  1. Weasler macrumors newbie

    Joined:
    Jul 25, 2007
    #1
    After programming on Windows for a while, I decided to come over to Mac and see port some of my work. But as it seems, for some reason XCode will not allow me to preform a simple task of making a Hello World application in Command Line C++. Here is a quick example (very very quick) of the language I know, and for some reason, it is not working, even though it works in Blodshed.

    #include <iostream>
    #include <stdlib.h>

    int main(int argc, char *argv[])
    {
    cout << "Hello World" << end1;
    return 0;
    }



    Any advice?
     
  2. After G macrumors 68000

    After G

    Joined:
    Aug 27, 2003
    Location:
    California
    #2
    shouldn't that "1" be an "L"?

    and i'd declare a namespace if I were you.

    oh yea, you don't need the standard library either.

    Code:
    #include <iostream>
    using namespace std;
    
    int main(int argc, char *argv[])
    {
    cout << "Hello World" << endl;
    return 0;
    }
     
  3. dcr macrumors member

    Joined:
    Jun 10, 2002
    #3
    in standards-compliant C++, iostream and therefore cout and endl are part of the std namespace.

    so you want

    std::cout

    instead of the global
    cout

    also, i think you mean to be using std::endl and not std::end1

    and generally speaking, avoid std::endl unless you need to explicitly flush the iostream immedately. you're often better off using the standard newline \n

    http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#2
     

Share This Page