Newbie C++ in Xcode

Discussion in 'Mac Programming' started by funnie, Jan 20, 2007.

  1. macrumors newbie

    Joined:
    Jan 20, 2007
    #1
    Hi everyone,

    i am taking a beginner course in C++ programming but my course uses software in the windows environment.

    I know this has come up many times, but i do appreciate if anyone could clarify things.

    1.
    I use Xcode.
    Is the correct project to create called ( C++ Tool ) under the Command Line Utility?

    2.
    I have some basic code that works in windows but not on my mac.
    This program copies the contents of a file and outputs a new file.
    ------------------------------------------------------------
    #include <fstream>
    #include <string>

    int main()
    {

    ifstream infile("in");
    ofstream outfile("out");
    string s;
    while (getline(infile,s))
    outfile << s << endl;

    return 0;
    }
    ------------------------------------------------------------

    Is something fundamentally wrong with my code? Or is it different on MAC?

    Thanks a lot!
     
  2. macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #2
    Hi

    Yes, C++ tool is the right project for what you are trying to do.

    Try putting:-

    using namespace std ;

    after your #includes.

    Or specify the namespace directly, eg std::ifstream infile("in");

    b e n
     
  3. macrumors 6502a

    LtRammstein

    Joined:
    Jun 20, 2006
    Location:
    Denver, CO
    #3
    Don't forget to indent and comment your code.

    Good luck with your class!

    Steve
     

Share This Page