Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to multiple space lines in the output file in C++


Adding Multiple New Lines to a String

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...


        #1 |   cout << "\n\n\n";
        #2 |   cout << endl << endl << endl;

like image 434
H'H Avatar asked Jul 08 '13 09:07

H'H


1 Answers

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' );
like image 164
log0 Avatar answered Sep 22 '22 13:09

log0