0
Is it necessary to write cout each time we use \n
6 Antworten
+ 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;
+ 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 ".
+ 4
@Bebida
That works too.
I have not tried using it like that yet.
I plan to try it.
+ 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.
+ 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.
0
As said by @Manual use padding in cout statements.