On C++ how do I make a space to separate each sentence that is descending? Hello World! My name is Joshua. How are you today?

2019-09-12 12:43 pm
更新1:

On C++ how do I make a space to separate each sentence that is descending? Hello World! My name is Joshua. How are you today?

更新2:

On C++ how do I make a space to separate each sentence that is descending? Hello World! My name is Joshua. How are you today?

回答 (5)

2019-09-12 2:19 pm
Write cout << "\n";
\n skips a line, this is used in almost all languages.
2019-09-12 12:51 pm
\n just like any other language
2019-09-12 1:12 pm
What is a "sentence that is descending"? I don't see any pattern in your example.

What I do see is 2 blank lines, a sentence, 1 blank line, a second sentence, 1 blank line and a final sentence. I don't see anything in the sentences that is descending, other than the top-to-bottom reading order.
2019-09-22 4:53 pm
what do you mean by descending ??

for creating a new line, just cout endl, or '\n' if you want to save space
2019-09-12 10:24 pm
Your instructor is probably looking for you to use endl, which is the C++ keyword for ending a line:
cout << "Hello World" << endl << endl;
cout << "My name is Joshua" << endl << endl;

Using the '\n' escape character inserts a New Line character in the character string. In some older systems New Line was strictly interpreted as a new line. It would scroll to a new line, but not return the print position to the beginning of the new line. So you also had to insert a Carriage Return character, so it would be "\n\r".
On Unix/Linux systems '\n' is always interpreted as Carriage Return and New Line. But on Windows systems they sometimes use "\n\r", so there can be some portabilibility issues.
The C++ abstraction to avoid these occasional portability issues is: endl
2019-09-12 5:04 pm
You can just append \n to the String:

cout << "HelloWorld!\n\n";

This adds two line breaks.


收錄日期: 2021-04-18 18:18:46
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20190912044338AAx0128

檢視 Wayback Machine 備份