Thread: Endl - Undeclared identifier.

  1. #1
    the Wizard
    Join Date
    Aug 2004
    Posts
    109

    Endl - Undeclared identifier.

    I have this code, where I use endl to go to a newline. Pretty simple, usually I don't get such an error but suddenly my project has begun to give my an error on every line that i use endl.

    Code:
      cout << "Mathematical Manager:\n";
      cout << "---------------------\n\n";
      cout << "Select problem type: " << endl;
      cout << "1. Rectangular Triangles" << endl;
      cout << "2. Circle Equation" << endl;
      cout << "3. Quadratic Equation" << endl;
    Here's the part of my code where I first got the error(title). Then I tried to change the endl, to \n (as you see in the first two lines), that helped.

    What could be wrong? I would like to be able to use endl, because that's what I've always used.

    Thx in advance.
    -//Marc Poulsen -//MipZhaP

    He sat down, he programmed, he got an error...

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    184
    have u included the

    Code:
    using namespace:: std
    at the top your code

    make sure about this

    s.s.harish

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Even better, don't defile the global namespace at all:
    Code:
    std::cout << "Blah!" << std::endl;
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    the Wizard
    Join Date
    Aug 2004
    Posts
    109
    Well I use a middle between you two.
    I write using std::endl;
    And yes, that was what I'd sadly forgotten.

    Remembered all the others though. :S
    Thx for reminding me
    -//Marc Poulsen -//MipZhaP

    He sat down, he programmed, he got an error...

  5. #5
    Registered User
    Join Date
    Mar 2005
    Posts
    6
    *wavies*

    Hi, new person here.

    I was wondering, could someone explain to me the significance of namespaces? I know when to use them and the like, but I don't understand _why_.

    Thanks,
    Inside

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Assume you have two files, a.h and b.h both developed by different programmers who knows nothing about the other's code:
    a.h
    Code:
    const int a = 1;
    const int b = 2;
    const int c = 3;
    b.h
    Code:
    const int c = 1;
    const int d = 2;
    const int e = 3;
    If you include both of these in your code you'll get compiler errors, multiple definitions of c.

    Now assume the two programmers used namespaces:

    a.h
    Code:
    namespace a
    {
      const int a = 1;
      const int b = 2;
      const int c = 3;
    }
    b.h
    Code:
    namespace b
    {
      const int c = 1;
      const int d = 2;
      const int e = 3;
    }
    Everything will be fine, no more name collisions.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  7. #7
    Registered User
    Join Date
    Mar 2005
    Posts
    6
    Oooooh..
    If I wanted to ... I could define my own namespace "inside" where the operators cout, etc, do different things. Right?

  8. #8
    Registered User
    Join Date
    Sep 2004
    Posts
    197
    Quote Originally Posted by InsideTheAsylum
    Oooooh..
    If I wanted to ... I could define my own namespace "inside" where the operators cout, etc, do different things. Right?
    You can't (shouldn't) make changes inside the std namespace. They are they way they are because they are the standard.
    If any part of my post is incorrect, please correct me.

    This post is not guarantied to be correct, and is not to be taken as a matter of fact, but of opinion or a guess, unless otherwise noted.

  9. #9
    Registered User
    Join Date
    Mar 2005
    Posts
    6
    I meant.. naming a namespace inside not make a change "inside" the namespace..

    Oi, it's confusing :P. I just use "inside" as my online nickname ;P

  10. #10
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    You can create whatever namespaces you want. Even nest them:
    Code:
    namespace eat
    {
      namespace my
      {
        void shorts();
      }
    }
    
    eat::my::shorts();
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM