-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringer.cpp
More file actions
59 lines (44 loc) · 1.07 KB
/
stringer.cpp
File metadata and controls
59 lines (44 loc) · 1.07 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
49
50
51
52
53
54
55
56
57
58
59
#include <boost/lexical_cast.hpp>
#include <boost/format.hpp>
#include <string>
#include <iostream>
#include <sstream>
class S {
public:
S()
{}
std::ostream& stream() {
return oss_;
}
std::string str() const {
return oss_.str();
}
operator std::string() const {
return str();
}
operator const char*() const {
return str().c_str();
}
private:
std::ostringstream oss_;
};
template<class T>
S& operator << (S& s, const T& t) {
s.stream() << t;
return s;
}
std::ostream& operator << (std::ostream& os, const S& s) {
os << s.str();
return os;
}
namespace {
int main() {
for (size_t i = 0; i < 20; ++i) {
const std::string oldFileName = "myfile_" + boost::lexical_cast<std::string>(i) + ".data";
const std::string newFileName = (S() << "myfile_" << i << ".data");
const std::string newerFileName = boost::str(boost::format("myfile_%1%.data") % i);
std::cout << oldFileName << " vs " << newFileName << " vs " << newerFileName << "\n";
}
return 0;
}
}