Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

EXAM PREPARATION DOUBTS : endl-Inserts a new-line character. Additionally, for buffered streams, endl flushes the buffer (i.e. writes all unwritten characters in the buffer to the output sequence,) .. why do we need to flush the buffer can i get an example so that I understand the use of endl ?Is endl a function .If yes what is its header file ? Its my final lab exam today ! Pray for me ! :)

Computer Science
See more answers at
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly


Get your free account and access expert answers to this and thousands of other questions

how is endl useful when working with files ?
How do I explain this... Okay. So endl means end line and it renders the output so the next output will start from a new line. ``` int main() { cout << "I sleep." << endl; cout << "On a bed."; return 0; } Output: I sleep. On a bed. Now if you removed endl and your code looked like: int main() { cout << "I sleep. "; cout << "On a bed."; return 0; } Output: I sleep. On bed. ``` So you can think of endl like the enter key to make a new line.

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

well then whats the difference between "\n" and endl ?
Silly :3 endl is only for C++. \n is for C you use the \n in printf to do the same thing. (Make the output look the same.)
but what do they say abt the buffer part ?
why is cleaning buffer necessary ?
Flushing the buffer is necessary, because the user will see the output written to the stream immediately. Output is generally buffered before it's written to the intended device. That way, when writing to slow to access devices(like files), it doesn't have to access the device after every single character. Flushing means emptying the buffer and actually writing it to the device. Check this: Read: (Benjamin Lindley's answer)
so when all should i use endl when working with files ?
i usually us \n for my programs
\n doesn't flush output buffer... endl does.
So if your using files I'd use endl. But otherwise I'd go with \n
flushing of buffer increases speed?
Somewhat. And especially when working with files. "That way, when writing to slow to access devices(like files), it doesn't have to access the device after every single character."
Question 2: My following code always gives o/p "as file does not exist" any solution ?
#include #include #include void main() { char f1[20],f2[20]; char ch; cout<<"\n\nEnter original file name:"; cin>>f1; cout<<"\nFile copy:"; cin>>f2; ifstream in(f1); ofstream out(f2); if( { cout<<"File does not exist "; exit(1); } while(!in.eof()) { in>>ch; out<
std::endl is more portable than hard coding '\n'. Even after all these years Unix uses a linefeed, Windows uses carriage return line feed together and some Mac GUIs still use carriage returns to end a line. std::endl is probably defined as whatever the OS specifies for ending a line.
@Opcode ....
urgent :can u identify error in my program below its not working either #include #include class distance { int m,cm; public: void read(); void operator +(distance); void display(); }; void distance::read() { cout<<"\n\nEnter distances:"; cin>>m>>cm; } void distance::display() { cout<<"\n distances:"; cout<=100) { temp.m+=1;; } } void main() { distance d3,d4,d5;;; d5=d3+d4; d5.display(); getch(); }
well my teacher told me instead of using for loop to input data to file char c[200] outfile out; for(i=0;c[i]!='\0';i++) { cin>>c[i]; out<
Wait. So like: ``` #include using namespace std; int main() { string input; while (true) { cout << "Type your input: "; while (getline(cin, input)) cout << input << endl; } return 0; } ```
i dunno is that the method ?

Not the answer you are looking for?

Search for more explanations.

Ask your own question