When submitting a solution in C++, please select either C++14 (GCC 6-32) or C++17 (GCC 7-32) as your compiler. ×

code_warrior's blog

By code_warrior, history, 4 years ago, In English

Can anyone explain what we should prefer "\n" or '\n' for adding a newline character or both are actually the same thing?

  • Vote: I like it
  • -37
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it +11 Vote: I do not like it

Search google first result smh.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I had googled but can't understand the idea. Please if someone knows ,share his idea. Feel free to downvote as most people do to newbie .

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +4 Vote: I do not like it

    According to what i gathered from the stack overflow thread you can do the following two

    1.> while adding a new line after any numerical datatype use '\n'. example : cout << "age = " << age << '\n'; // more efficient than cout << "age = " << age << "\n";

    2.> If adding a newline after printing a string you can do cout<<"checkoutput \n";