jleedev
-
C++,
pasted
on Jul 30:
|
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// Add printing capabilities to pair ...
template<class T, class U>
ostream& operator<<(ostream& out, const pair<T,U>& p) {
return out << '(' << p.first << ',' << p.second << ')';
}
// ... and to vector ...
template<class T>
ostream& operator<<(ostream& out, const vector<T>& v) {
out << '[';
typename vector<T>::const_iterator it = v.begin();
while (it != v.end()) {
out << *it;
if (++it != v.end()) out << ',';
}
return out << ']';
}
// Oh dear.
int main() {
string s1 = "hello";
string s2 = "templates";
vector<pair<char,char> > v(min(s1.length(),s2.length()));
transform(s1.begin(), s1.end(), s1.begin(), ::toupper);
transform(s1.begin(), s1.end(), s2.begin(), v.begin(), make_pair<char,char>);
cout << s1 << endl;
cout << s2 << endl;
cout << v << endl;
}
|
Output:
|
HELLO
templates
[(H,t),(E,e),(L,m),(L,p),(O,l)]
|
|