Is there a more appealing syntax — or a syntax that is less repetitive — for inserting multiple new lines
into a string than the two methods I use, which are...
cout << "\n\n\n";
cout << endl << endl << endl;
No there are no special facilities for adding multiple space lines. you can do this:
std::cout << "\n\n\n\n\n";
or this
for (int i = 0; i < 5; ++i)
std::cout << "\n";
or implement your own operator*
std::string operator*(std::string const &s, std::size_t n)
{
std::string r;
r.reserve(n * s.size());
for (std::size_t i = 0; i < n; ++i)
r += s;
return r;
}
std::cout << (std::string("\n") * 5);
finally, recommended solution:
std::cout << std::string( 5, '\n' );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With