-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringStream.cpp
More file actions
41 lines (33 loc) · 771 Bytes
/
StringStream.cpp
File metadata and controls
41 lines (33 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <sstream>
#include <string>
namespace {
void run() {
std::cout << "\n--- String Stream Example ---\n";
std::stringstream os{};
// input
os << "0xF";
std::cout << os.str();
// Note: After changing .str(), always call .clear() before reading.
os.str("0x1 0x2");
os.clear();
std::cout << os.str();
// output
std::string bytesStr = os.str();
std::cout << bytesStr;
os.str("0x0 0xF 0xE 0x2");
os.clear();
os >> bytesStr;
std::cout << bytesStr;
// conversions
int byte_low = 0xFFF;
int byte_high = 0x001;
os.clear();
os << byte_low << ' ' << byte_high;
std::cout << os.str();
}
} // namespace
struct StringStreamRunner {
StringStreamRunner() { run(); }
};
static StringStreamRunner autoRunner;