Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- в моей студио почему - то не запускатеся ? !
- #include <iostream>
- #include <vector>
- #include <map>
- #include <sstream>
- #include <utility>
- #include <fstream>
- using namespace std;
- template <typename Collection>
- string Join(const Collection& c, char d)
- {
- stringstream ss; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- bool first = true; // флаг, который говорит первый мы выводим элемент или нет
- for (const auto& i : c)
- {
- if (!first)
- {
- ss << d; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- }
- first = false;
- ss << i; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- }
- return ss.str(); !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- }
- template <typename First, typename Second>
- ostream& operator<< (ostream& out, const pair<First, Second>& p)
- {
- return out << '(' << p.first << ',' << p.second << ')';
- }
- template <typename T>
- ostream& operator<< (ostream& out, const vector<T>& vi)
- {
- return out << '[' << Join(vi, ',') << ']';
- }
- template <typename Key, typename Value>
- ostream& operator<< (ostream& out, const map<Key, Value>& m)
- {
- return out << '{' << Join(m, ',') << '}';
- }
- int main()
- {
- vector<double> vi = { 1.4, 2, 3 };
- cout << vi << endl;
- map<int, double> m = { {1, 2.5}, {3, 4} };
- cout << m << endl;
- vector<vector<int>> v = { {1, 2}, {3, 4} };
- cout << v << endl;
- vector <string> w = { "helo", "world", "me" };
- cout << w << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement