endl in <iofstream>

I wonder if <iostream>'s function "endl" has a different encoding across different OS or different compilers.

Can you please just test codes below under windows?

Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <fstream>
#include <ios>
using namespace std;


int main()
{

	fstream file;
	file.open("file.txt", ios::out);
	file<<"\n\n";
        file<<endl<<endl;
	file.close();


	char ch;
	file.open("file.txt", ios::in);
	while(file.get(ch))
		cout<<"ch="<<ch<<" int(ch)="<<int(ch)<<"\n";
	file.close();

	return 0;
}


under Ubuntu the output is:

ch=
 int(ch)=10
ch=
 int(ch)=10
ch=
 int(ch)=10
ch=
 int(ch)=10
I wonder if <iostream>'s function "endl" has a different encoding across different OS or different compilers.
Yes, it does. Sort of. In reality the conversion is done at level lower than that function.
If you just look at the output, std::endl and '\n' are synonyms.
Topic archived. No new replies allowed.