Thread: Simplest question you will ever have to answer...

  1. #1
    2 days into C++
    Join Date
    Dec 2005
    Location
    San Francisco, CA
    Posts
    2

    Simplest question you will ever have to answer...

    Hi, I'm learning C++, and I copied the code below out of a book I am learning from. It gives me the errors:
    15 C:\Dev-Cpp\Projects\FirstProject\main.cpp `cout' undeclared (first use this function)
    15 C:\Dev-Cpp\Projects\FirstProject\main.cpp `endl' undeclared (first use this function)
    when I try to compile it (in Dev-C++).

    Here is the source code:

    Code:
    #include <iostream>
    #include <stdlib.h>
    int AddOne(int start)
    {
        int newnumber;
        newnumber = start + 1;
        return newnumber;
    }
    int main(int argc, char *argv[])
    {
        int testnumber;
        int result;
        testnumber = 20;
        result = AddOne(testnumber);
        cout << result << endl;
        system("PAUSE");
        return 0;
    }
    Can you tell me what's causing the problem? I just started learning C++ a day ago, and I haven't a clue what is wrong with this source code. Thank you soooo much!! It is probably a silly thing that I forgot to put in...
    Last edited by mattOmynameO; 12-17-2005 at 03:33 PM.

  2. #2
    Registered User
    Join Date
    Dec 2005
    Posts
    1
    insert the line:

    using namespace std;

    right under the line: #include <stdlib.h>

    I'll let someone else explain what a namespace is.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    We wouldn't even have to answer it if you browser the FAQ a little.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    2 days into C++
    Join Date
    Dec 2005
    Location
    San Francisco, CA
    Posts
    2
    Quote Originally Posted by CornedBee
    We wouldn't even have to answer it if you browser the FAQ a little.
    I'm sorry... I didn't see the FAQ... -.-

    And thank you for the helpful reply, ghosttownvoid. I appreciate it a lot.

  5. #5
    Registered User
    Join Date
    Mar 2005
    Posts
    17
    Opening completly a namespace in the global scope is not a such good idea.
    Consider using the using namespace directive inside the main block

    or just using using std::cout and using std::endl

  6. #6
    Registered User
    Join Date
    Nov 2005
    Posts
    85
    looks so messy using std::cout, one line to solve and make code more readable

  7. #7
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    So does it works like this?
    Code:
    using namespace something;
    // all the code here has something::
    using namespace something2;
    // all the code here has something2::
    , or like this :
    Code:
    using namespace something;
    // all the code here has something::
    using namespace something2;
    // all the code here has something::
    // all the code here has something2::
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. some question asking for answer...
    By mat13mat in forum C++ Programming
    Replies: 6
    Last Post: 04-30-2008, 03:40 AM
  2. C++ Question with uncomplete answer..anyone can solve it?
    By jason07 in forum C++ Programming
    Replies: 9
    Last Post: 09-13-2005, 04:56 PM
  3. Can anyone help me to answer this question
    By I_need_help in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 02-06-2003, 11:12 PM
  4. Please Answer My Question:
    By DeanDemon in forum C++ Programming
    Replies: 2
    Last Post: 12-17-2002, 12:50 AM
  5. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM