Jump to content
  • Advertisement
Sign in to follow this  
SmokeyX28

Anyone know how to fix this error?

This topic is 4116 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im doing some simple exercises (just starting to learn programming) and i keep getting these 3 errors and cant figure out how to fix it, it says "error: 'endl' undeclared (first use this function)" line 6 and "error: (each undeclared identifier is reported only once for each function is appears in)" line 6 the third error is the same as the first one i listed only on line 8. heres the code i have typed out, its just a little exercise im supposed to do asking me to run this and see what it does, but it wont run because of that error. #include <iostream> int main() { int x = 5; int y = 7; std::cout << endl; std::cout << x + y << " " << x * y; std::cout << end; return 0; } anyone know what the problem might be?

Share this post


Link to post
Share on other sites
Advertisement
use:
std::endl

or

at the top of the file, write:
using namespace std;
then you dont need to put 'std::' in from of 'cout' and 'endl'

Share this post


Link to post
Share on other sites
xsirxx has your answer for you.

Consider where endl comes from (I'll give you a hint, it's in the std namespace, just like cout) -- hence, in order to get at it, you need to say that you want to use members of namespace std (stick 'using namespace std;' above your main function').

Or given that you're accessing cout explicitly by using std::cout, you could access endl using std::endl. As for 'end', you sure that's not a typo...?

~Shiny

Share this post


Link to post
Share on other sites
Awesome, thanks for the help guys, i got it.

i added the "using namespace std;" removed the other std::'s and added an "l" after the "end" on line 8, the book here must have had a type or something, because it said to just put "std::cout << end;" on line 8.

heres what i did.

#include <iostream>
int main()
{
using namespace std;
int x = 5;
int y = 7;
cout << endl;
cout << x + y << " " << x * y;
cout << endl;
return 0;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by SmokeyX28
the book here must have had a type or something


Yeah, books are frequently just plain wrong. Code gets typed up by non-programmers, and important details are sometimes lost (because the person responsible doesn't know what's important). The down side with books is that once published, it's a major undertaking to correct any errors ;)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!