endl not working for me!

********NOOB ALERT!********

Howdy folks, just a few days into my C++ journey!

I don't seem able to add line breaks, anyone know what i'm doing wrong?!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include "stdafx.h"
 
 
#include <iostream>
int main()
{
    int x;
    x = 8;
    std::cout << x << endl;
        return 0; 
}
/*1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------
1>  ConsoleApplication1.cpp
1>c:\c\consoleapplication1\consoleapplication1.cpp(12): error C2065: 'endl': undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========*/

std::endl
Please show me the entire code as it needs to be!........ thanks!

Learncpp.com does it like this:

std::cout << x << endl;

??
Last edited on
Yes i read it, i tried it, it didn't work, probably because my whole code wasn't correct.

Remember, i'm a beginner and this is the beginners forum! :)

This is what i did:

1
2
3
4
5
6
7
8
9
10
11
#include "stdafx.h"


#include <iostream>
int main()
{
	int x;
	x = 8;
	std::endl << x;
		return 0; 
}

1
2
3
4
5
6
7
8
9
10
11
#include "stdafx.h"
 
 
#include <iostream>
int main()
{
    int x;
    x = 8;
    std::cout << x << std::endl;
        return 0; 
}
Great, thank you muchos, i guess it's time to read the "endl, the std " page on Learncpp.com!

Still curious why std::cout << x << endl; as shown on Learncpp.com didn't work, see here:

http://www.learncpp.com/cpp-tutorial/13-a-first-look-at-variables/

Last edited on
Because endl is defined within the namespace std. This means to the compiler, endl and std::endl are completely different things. Basically, all standard library things need to be prefixed with std:: because they often have names that you might want to use for your own functions (such as begin and end) and the std:: allows the compiler to recognise that the standard library endl is what you are looking for.
Notice that you are not given a complete program, only small snippet. There wass something allowing std::endl be found by unqualified lookup.
Thanks for the replys / information, this is gonna be a long road but i feel i've now made a start!
Topic archived. No new replies allowed.