-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringStream.cpp
More file actions
48 lines (38 loc) · 1.11 KB
/
Copy pathStringStream.cpp
File metadata and controls
48 lines (38 loc) · 1.11 KB
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
42
43
44
45
46
47
48
#include <iostream>
#include <sstream>
#include <string>
#include "ExampleRegistry.h"
namespace {
void runStringStreamExample() {
std::cout << "\n--- String Stream Example ---\n";
std::stringstream os{};
// input: std::istringstream iss;
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::ostringstream oss;
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
class StringStream : public IExample {
public:
std::string group() const override { return "core/filehandle"; }
std::string name() const override { return "StringStream"; }
std::string description() const override { return ""; }
void execute() override { runStringStreamExample(); }
};
REGISTER_EXAMPLE(StringStream, "core/filehandle", "StringStream");