Skip to content

Commit a96d778

Browse files
Merge pull request #4663 from TylerMSFT/wistream
add range adaptor example for wistream_view
2 parents 9f42987 + 9180fe1 commit a96d778

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

docs/standard-library/basic-istream-view-class.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,28 @@ The best way to create a `basic_istream_view` is by using the [`views::istream`]
117117
### Example: `basic_istream_view`, `istream_view`, and `wistream_view`
118118
119119
```cpp
120-
121-
```cpp
122-
// requires /std:c++20 or later
123120
#include <ranges>
124121
#include <iostream>
125122
#include <sstream>
126123
127124
int main()
128125
{
129126
// range adaptor
130-
std::istringstream doubles{ "1.1 2.2 3.3 4.4 5.5" };
131-
for (const auto& elem : std::views::istream<double>(doubles))
127+
std::istringstream streamOfdoubles{ "1.1 2.2 3.3 4.4 5.5" };
128+
for (const auto& elem : std::views::istream<double>(streamOfdoubles))
132129
{
133130
std::cout << elem << ' '; // 1.1 2.2 3.3 4.4 5.5
134131
}
135132
std::cout << '\n';
136133
134+
// range adaptor - create a wistream_view
135+
std::wistringstream streamOfInts{ L"1 2 3 4 5" };
136+
for (const auto& elem : std::views::istream<int>(streamOfInts))
137+
{
138+
std::cout << elem << ' '; // 1 2 3 4 5
139+
}
140+
std::cout << '\n';
141+
137142
// istream_view alias
138143
std::istringstream cpu1{ "8 0 8 0" };
139144
// equivalent std::ranges::istream_view<int, char>
@@ -142,7 +147,7 @@ int main()
142147
std::cout << elem; // 8080
143148
}
144149
std::cout << '\n';
145-
150+
146151
// wistream_view alias
147152
std::wistringstream cpu2{ L"6 5 0 2" };
148153
// equivalent std::ranges::istream_view<int, wchar_t>
@@ -157,13 +162,14 @@ int main()
157162
std::ranges::basic_istream_view<wchar_t, wchar_t, std::char_traits<wchar_t>> basic{misc};
158163
for (const auto& elem : basic)
159164
{
160-
std::wcout << elem << ' '; // STL
165+
std::wcout << elem << ' '; // S T L
161166
}
162167
}
163168
```
164169

165170
```output
166171
1.1 2.2 3.3 4.4 5.5
172+
1 2 3 4 5
167173
8080
168174
6502
169175
S T L

0 commit comments

Comments
 (0)