none
error C2065: 'endl' : undeclared identifier-error C2065: 'end' : undeclared identifier

    Question

  • I am new at C++ and I am having a little problem with Visual C++ 2005.

    I type in this source code

    #include <iostream>

    int main()

    {

    int x = 5;

    int y = 7;

    std::cout << endl;

    std::cout << x + y << " " << x * y;

    std::cout << end;

    return 0;

    }

    When I build my program I get two errors and those are

    error C2065: 'endl' : undeclared identifier

    error C2065: 'end' : undeclared identifier

    What is the problem and how can I fix it?

     

    Sunday, March 18, 2007 5:05 AM

Answers

  • try adding: std:: before both of your endl's (Oh and, check your typo on the 2nd endl =P)


    #include <iostream>

    int main()
    {

    int x = 5;

    int y = 7;

    std::cout << std::endl;

    std::cout << x + y << " " << x * y;

    std::cout << std::endl;

    return 0;

    }

    Sunday, March 18, 2007 5:33 AM
  • Or do the following:

    #include <iostream>
    using namespace std;

    This will alleviate having to use std:: in all places.

    Sunday, March 18, 2007 2:37 PM
    Moderator

All replies

  • try adding: std:: before both of your endl's (Oh and, check your typo on the 2nd endl =P)


    #include <iostream>

    int main()
    {

    int x = 5;

    int y = 7;

    std::cout << std::endl;

    std::cout << x + y << " " << x * y;

    std::cout << std::endl;

    return 0;

    }

    Sunday, March 18, 2007 5:33 AM
  • Or do the following:

    #include <iostream>
    using namespace std;

    This will alleviate having to use std:: in all places.

    Sunday, March 18, 2007 2:37 PM
    Moderator
  • Or you could do the following, which would alleviate having to qualify using std:: in all places:

    #include <iostream>
    using namespace std;

     

    Sunday, March 18, 2007 2:38 PM
    Moderator
  • Hi,

    the otherway is using name space std as follows

    ===========================

    #include <iostream>

    using namespace std; //Now , u don't need to use std:: any where .

    int main()

    {

    int x = 5;

    int y = 7;

    cout << endl;

    cout << x + y << " " << x * y;

    cout << endl;

    return 0;

    }

    ==================

     

    Thanx,

    Ch.T.Gopi Kumar.

    Sunday, March 18, 2007 3:32 PM
  • Thanks

    Jhiither

    Monday, February 21, 2011 3:57 PM
  • Do you need to specify std namespace? i.e. std::endl ?

    Giovanni

    Monday, February 21, 2011 4:10 PM
  • I can not use namespace end one it will not work I have tried declaring it tried it in differnt lines it will not work.

    //The Author of the book sams C++ shows using end1 in this way. This is supposed to make it print on the next line. 

    cout <<"Width: " << Width <<end1;

     

    -------------------------------------------------------------------------------

    // Demonstration of variables

    #include

     

     

    <iostream>

    int

     

     

    main()

    {

     

     

    using namespace std;

     

     

    unsigned short int Width = 5, Length;

    Length = 10;

     

     

    // create an unsighed short and initialize with result

     

     

    //of multiplying Width by Lengh

     

     

    unsigned short int Area = (Width * Length);

    cout <<

     

    "Width: "<< Width ;

    cout <<

     

    "Length: " << Length ;

    cout <<

     

    "Area: " << Area << ;

    cout << end1;

     

     

    return 0;

    }

     

    >------ Rebuild All started: Project: listing 3.2, Configuration: Debug Win32 ------

    1> Listing3.2.cpp

    1>c:\users\jeff\documents\visual studio 2010\projects\listing 3.2\listing 3.2\listing3.2.cpp(17): error C2059: syntax error : ';'

    1>c:\users\jeff\documents\visual studio 2010\projects\listing 3.2\listing 3.2\listing3.2.cpp(18): error C2065: 'end1' : undeclared identifier

     

     


    Jeffery J. Hiither
    Thursday, February 24, 2011 1:49 AM
  • It is not "end one" (end1) it is "end el" (endl).
    Think of "end l(ine)".

    - Wayne
    Thursday, February 24, 2011 2:52 AM