Skip to content

Commit deec731

Browse files
authored
Merge pull request #3822 from TylerMSFT/tylermsft-github3434
fix github issue #3434
2 parents f667e0c + 5107709 commit deec731

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

docs/standard-library/using-insertion-operators-and-controlling-format.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
---
22
description: "Learn more about: Using Insertion Operators and Controlling Format"
33
title: "Using Insertion Operators and Controlling Format"
4-
ms.date: "11/04/2016"
4+
ms.date: 10/07/2021
55
helpviewer_keywords: ["insertion operators"]
6-
ms.assetid: cdefe986-6548-4cd1-8a67-b431d7d36a1c
76
---
87
# Using Insertion Operators and Controlling Format
98

@@ -81,14 +80,14 @@ using namespace std;
8180
int main( )
8281
{
8382
double values[] = { 1.23, 35.36, 653.7, 4358.24 };
84-
char *names[] = { "Zoot", "Jimmy", "Al", "Stan" };
83+
const char *names[] = { "Zoot", "Jimmy", "Al", "Stan" };
8584
for( int i = 0; i < 4; i++ )
8685
cout << setw( 7 ) << names[i]
8786
<< setw( 10 ) << values[i] << endl;
8887
}
8988
```
9089
91-
The `width` member function is declared in `<iostream>`. If you use `setw` or any other manipulator with arguments, you must include `<iomanip>`. In the output, strings are printed in a field of width 6 and integers in a field of width 10:
90+
The `width` member function is declared in `<iostream>`. If you use `setw` or any other manipulator with arguments, you must include `<iomanip>`. In the output, strings print in a field of width 6 and integers in a field of width 10:
9291
9392
```Output
9493
Zoot 1.23
@@ -97,7 +96,7 @@ The `width` member function is declared in `<iostream>`. If you use `setw` or an
9796
Stan 4358.24
9897
```
9998

100-
Neither `setw` nor `width` truncates values. If formatted output exceeds the width, the entire value prints, subject to the stream's precision setting. Both `setw` and `width` affect the following field only. Field width reverts to its default behavior (the necessary width) after one field has been printed. However, the other stream format options remain in effect until changed.
99+
`setw` and `width` don't truncate values. If formatted output exceeds the width, the entire value prints, subject to the stream's precision setting. Both `setw` and `width` affect the following field only. Field width reverts to its default behavior (the necessary width) after one field has been printed. However, the other stream format options remain in effect until changed.
101100

102101
## <a name="vclrfalignmentanchor4"></a> Alignment
103102

@@ -177,11 +176,11 @@ Again, the program prints one digit after the decimal point. If either `ios::fix
177176

178177
## <a name="vclrfradixanchor6"></a> Radix
179178

180-
The `dec`, `oct`, and `hex` manipulators set the default radix for input and output. For example, if you insert the `hex` manipulator into the output stream, the object correctly translates the internal data representation of integers into a hexadecimal output format. The numbers are displayed with digits a through f in lower case if the [`uppercase`](../standard-library/ios-functions.md#uppercase) flag is clear (the default); otherwise, they are displayed in upper case. The default radix is `dec` (decimal).
179+
The `dec`, `oct`, and `hex` manipulators set the default radix for input and output. For example, if you insert the `hex` manipulator into the output stream, the object correctly translates the internal data representation of integers into a hexadecimal output format. The numbers are displayed with digits a through f in lower case if the [`uppercase`](../standard-library/ios-functions.md#uppercase) flag is clear (the default); otherwise, they're displayed in upper case. The default radix is `dec` (decimal).
181180

182181
## Quoted strings (C++14)
183182

184-
When you insert a string into a stream, you can easily retrieve the same string back by calling the `stringstream::str()` member function. However, if you want to use the extraction operator to insert the stream into a new string at a later point, you may get an unexpected result because the `>>` operator by default will stop when it encounters the first whitespace character.
183+
When you insert a string into a stream, you can easily retrieve the same string back by calling the `stringstream::str()` member function. However, if you want to use the extraction operator to insert the stream into a new string at a later point, you may get an unexpected result because the `>>` operator by default will stop when it finds the first whitespace character.
185184

186185
```cpp
187186
std::stringstream ss;
@@ -195,11 +194,11 @@ std::cout << inserted; // This is a sentence.
195194
std::cout << extracted; // This
196195
```
197196

198-
This behavior can be overcome manually, but to make string round-tripping more convenient, C++14 adds the `std::quoted` stream manipulator in `<iomanip>`. Upon insertion, `quoted()` surrounds the string with a delimiter (double quote ' " ' by default) and upon extraction manipulates the stream to extract all characters until the final delimiter is encountered. Any embedded quotes are escaped with an escape character ('\\\\' by default).
197+
This behavior can be overcome manually, but to make string round-tripping more convenient, C++14 adds the `std::quoted` stream manipulator in `<iomanip>`. Upon insertion, `quoted()` surrounds the string with a delimiter (double quote ' " ' by default) and upon extraction manipulates the stream to extract all characters until the final delimiter is found. Any embedded quotes are escaped with an escape character ('\\\\' by default).
199198

200-
The delimiters are present only in the stream object; they are not present in the extracted string but they are present in the string returned by [`basic_stringstream::str`](../standard-library/basic-stringstream-class.md#str).
199+
The delimiters are present only in the stream object; they aren't present in the extracted string but they're present in the string returned by [`basic_stringstream::str`](../standard-library/basic-stringstream-class.md#str).
201200

202-
The whitespace behavior of the insertion and extraction operations is independent of how a string is represented in code, so the quoted operator is useful regardless of whether the input string is a raw string literal or a regular string. The input string, whatever its format, can have embedded quotes, line breaks, tabs, and so on and all these will be preserved by the `quoted()` manipulator.
201+
The whitespace behavior of the insertion and extraction operations is independent of how a string is represented in code, so the quoted operator is useful regardless of whether the input string is a raw string literal or a regular string. The input string, whatever its format, can have embedded quotes, line breaks, tabs, and so on, and all these will be preserved by the `quoted()` manipulator.
203202

204203
For more information and full code examples, see [`quoted`](../standard-library/iomanip-functions.md#quoted).
205204

0 commit comments

Comments
 (0)