KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm looking for practical and educational samples of C++ / STL code fitting in few lines. My actual favorites are: Empty a vector freeing its reserved memory: vector <...>().swap (v) (swap with a temporary) Copy a map to a vector: map<T1, T2> myMap; vector< pair<T1, T2> > myVec(myMap.begin(), myMap.end()); // or myVec.assign(myMap.begin(), myMap.end()); Custom, non-boost split: vector<string> &mysplit(const string &s, char delim, vector<string> &elems) { stringstream ss(s); string item; while(getline(ss, item, delim)) { elems.push_back(item); } return elems; }
Tags (comma-separated)
Save Edits
Cancel