CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2010
    Posts
    15

    Beginner need help with errors

    Need help, errors messages added as comments after line.

    #include <iostream>
    int Add (int x, int y)
    {
    cout << "In Add(), received " << x << " and " << y << "\n"; //Error C2065: 'cout' : undeclared identifier
    return (x+y);
    }
    int main()
    using namespace std; //Error C2143: syntax error : missing ';' before 'using'

    { //Error C2447: '{' : missing function header

    cout << "I'm in main()!\n";
    int a, b, c;
    cout << "Enter two numbers: ";
    cin >> a;
    cin >> b;
    cout << "\nCalling Add()\n";
    c=Add(a,b);
    cout << "\nBack in main().\n";
    cout << "c was set to " << c;
    cout << "\nExiting...\n\n";
    return 0;




    -------------------------------------------------------
    Another question,
    What is code tags and how do use them?
    Attached Images Attached Images  
    Last edited by Fnyx; October 26th, 2010 at 06:11 AM. Reason: Code tags

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Beginner need help with errors

    Please, replace this very bad made screenshot with an original code block (using Code tags of course!)
    Victor Nijegorodov

  3. #3
    Join Date
    Jan 2002
    Location
    Houston, TX
    Posts
    1,421

    Re: Beginner need help with errors

    First thing I see is that you are using cout in your Add function, but you haven't used the namespace yet.

    Two ways to start is to change
    Code:
    int Add (int x, int y)
    {
        cout << "In Add(), received " << x << " and " << y << "\n"; //Error C2065: 'cout' : undeclared identifier
        return (x+y);
    }
    to
    Code:
    int Add (int x, int y)
    {
        std::cout << "In Add(), received " << x << " and " << y << "\n"; //Error C2065: 'cout' : undeclared identifier
        return (x+y);
    }
    or you can move
    Code:
    using namespace std; //Error C2143: syntax error : missing ';' before 'using'
    just after the include
    Code:
    #include <iostream>
    using namespace std; //Error C2143: syntax error : missing ';' before 'using'
    Hope that helps.
    Be sure to rate those who help!
    -------------------------------------------------------------
    Karl - WK5M
    PP-ASEL-IA (N43CS)
    PGP Key: 0xDB02E193
    PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured