Skip to content

Instantly share code, notes, and snippets.

@tautologico
Last active February 16, 2017 14:09
Show Gist options
  • Save tautologico/2ed7901821d41a43f0835ba32e92add9 to your computer and use it in GitHub Desktop.
Save tautologico/2ed7901821d41a43f0835ba32e92add9 to your computer and use it in GitHub Desktop.
#include <sstream>
#include <vector>
#include <iterator>
#include <iostream>
using namespace std;
template <typename T>
vector<T> read_vector(const string& s) {
istringstream iss(s);
vector<T> result { istream_iterator<T>(iss), istream_iterator<T>() };
return std::move(result);
}
int main() {
string s = "Aftas arden Ausmachen dass den die Toten Hosen";
string sn = "145 67 32 99";
cout << "Strings: " << endl;
vector<string> tokens = read_vector<string>(s);
for (auto& t : tokens) {
cout << t << endl;
}
cout << endl;
cout << "Numeros: " << endl;
vector<int> nums = read_vector<int>(sn);
for (auto& n : nums) {
cout << n << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment