Home > Article > Backend Development > How to output two results in c++
The following method can be used to output multiple results in C: use the comma operator (,) to output the expression results one by one and separate them with spaces. Use the insertion operator (<<) and a stream object to insert multiple values into cout one after another for output. Use the printf function to output multiple results in a single function call using format specifiers.
How to output multiple results in C
To output multiple results in C, you can use the following method Implementation:
1. Use the comma operator (,)
The comma operator is used to connect multiple expressions and execute them in order. On output, the results of each expression are displayed separated by spaces. For example:
<code class="cpp">cout << "结果 1: " << 10 << ", 结果 2: " << 20 << endl;</code>
Output:
<code>结果 1: 10, 结果 2: 20</code>
2. Use the insertion operator (<<) and the stream object
insertion operator (< ;<) You can insert values into stream objects, such as cout
. Multiple results can be output by inserting multiple values into cout
. For example:
<code class="cpp">cout << "结果 1: " << 10 << " 结果 2: " << 20 << endl;</code>
Output:
<code>结果 1: 10 结果 2: 20</code>
3. Use the printf
function
printf
function to Format and output variables. By using format specifiers, you can output multiple results in a single function call. For example:
<code class="cpp">printf("结果 1: %d, 结果 2: %d\n", 10, 20);</code>
Output:
<code>结果 1: 10, 结果 2: 20</code>
Note: When using these methods, make sure the text or delimiters between the individual results are correct to provide clarity and ease of understanding Output.
The above is the detailed content of How to output two results in c++. For more information, please follow other related articles on the PHP Chinese website!