0

Is it necessary to write cout each time we use \n

26th Apr 2017, 4:39 PM
Aman
6 Réponses
+ 4
Yes. You want to go to a new line on console and it is consider an output and every output needs to be carried by cout stream to their destination (console) but there is an elegant and a little fancy way to do so, which is std::cout << std::endl;
26th Apr 2017, 4:44 PM
Babak
Babak - avatar
+ 4
Yes it is. For text you can use it for a new line. You can also use this: cout << x <<endl; "endl; " has the same effect as one " \n ".
26th Apr 2017, 4:47 PM
Manual
Manual - avatar
+ 4
@Bebida That works too. I have not tried using it like that yet. I plan to try it.
26th Apr 2017, 5:21 PM
Manual
Manual - avatar
+ 4
@Aman, You should continue with the course. The "std::" or the "file" will not help you now. It will make sense later on in the course.
26th Apr 2017, 5:24 PM
Manual
Manual - avatar
+ 2
Well i think not, if you are writing a file you would do sonething like fstream file{...}; // create file file << "a string with newline\n"; // write to file and there is no cout there.
26th Apr 2017, 4:50 PM
Bebida Roja
Bebida Roja - avatar
0
As said by @Manual use padding in cout statements.
26th Apr 2017, 4:48 PM
Nantha
Nantha - avatar