C++ #include help?

Discussion in 'Mac Programming' started by BlackBlade, Dec 5, 2011.

  1. BlackBlade, Dec 5, 2011
    Last edited by a moderator: Dec 5, 2011

    macrumors member

    Jan 4, 2010
    ok never used C++ before and i am using it far a college corse and i decided to use Xcode 4 based on the suggestions made on this site, I watched a tutorial on how to generally use c++ and i am familiar with python, i am wondering why no #include commands work. i have gone through aprox. 30 pages on google looking for an answer

    here is my code just in case
    #include <cmath>
    using manespace std;
    int main(void)
     double dnumber1 = 0.0;
     double dnumber2 = 0.0;
     double dnumber3 = 0.0;
     double average = 0.0;
     cout << "please enter 3 numbers: "; <<endl;
     cin >> dnumber1;
     cin >> dnumber2;
     cin >> dnumber3;
     daverage = (dmunber1 + dmunber2 + dnumber3) / 3;
     cout << "the average of the mumbers are: " << daverage << endl << endl
     return 0;
    and fyi i have tried math, math.h and iostream (iostream is th most used one i can find but it is not recognized, it says "iostream" file not found)
  2. macrumors 68040

    Feb 2, 2008
    What kind of error messages do you get that is related to cmath? The posted code is full of errors not related to the inclusion of cmath. Also nothing in the program requires cmath so you can leave that out, but you will need iostream.
  3. macrumors member

    Aug 8, 2011
    This isn't your exact code, is it?

    I can see a lot of typos. Namespace spelled wrong, wrong kind of parenthesis for the function body and a couple of lines with missing terminators.
  4. thread starter macrumors member

    Jan 4, 2010
    cmath related errors are simply this, "cmath" file not found, and iostream is not recognized, i then went through the whole list of include functions(not sure what to call them) and the closest thing on there is IOsurface or IOsurface.h

    this is my first time ever using C++ ever so yes this is my whole code, yet no errors occur or are shown except for the include statement (and i just noticed the typos my self and corrected them) also can u please elaborate on the parenthesis problem?
  5. macrumors 68040

    Feb 2, 2008
    Did you create a C++ project and not Objective-C or Cocoa? I you pick a Cocoa application you will get this error.
  6. thread starter macrumors member

    Jan 4, 2010
    i am an idiot, i figured it out, i never made a file in the project i simply used main.m
    just tried making a c++ file and it worked

    thanks a lot, now i won't fail! thanks again
  7. macrumors member

    Aug 8, 2011
    A function body should be contained in { } brackets, not ( ), which normally house the parameters for a functions.


    int main(void)
    // Code here

    I'm currently at work, so don't have my Mac at hand to identify and XCode specific issues, but I'm happy to look through this and give you a hand when I get home (probably 3 hours or so) if nobody else has done so by then.
  8. macrumors 68040

    Feb 2, 2008
    Good to hear, but you should not have a main.m file at all really. When you create a new project, pick "command line tool" then "C++".
  9. thread starter macrumors member

    Jan 4, 2010
    thanks again, and now i can actually make a working program, i never knew to use the command line tool i just used the default (which i believe is empty application)
  10. macrumors 68040

    Feb 2, 2008
    True, the default is set up for a Objective-C based Cocoa application, but you will be making a text based C++ application.
  11. macrumors newbie

    Dec 13, 2011

Share This Page