Category : stl

I’m trying to implement a hashtable. I understand list<int> *table is a pointer to list(entries), and in the constructor, I init the size of the list(represents how many entries). I’m very curious why this can be a list of list(2D list) structure, why I can perform table[key].push_back(…); Thanks class HashTable { private: int size; list<int> ..

Read more

I have following code, that fails due to read access violation: #include <vector> using namespace std; vector<int>::iterator myIterator; void foo(vector<int> vec) { myIterator = vec.begin(); // Maybe shallow copy? } int main() { foo({ 10, 20, 30, 40 }); *myIterator; // Here it fails. return 0; } After some debugging, I found, that myIterator becomes ..

Read more

here is the code for what i think should convert string "12 13 14 15" to integer 12131415 int takestring_makedigit(string s){ stringstream ss(s); char c,num; int final; string str=""; while (ss) { if(ss.peek()==’_’) { ss>>c; } else { ss>>num; str+=num; } } stringstream ss2(str); ss2>>final; return final; } however , this returns 123455 , which ..

Read more

For instance, #include <algorithm> #include <iostream> #include <numeric> #include <vector> int main() { std::vector<int> empty{}; std::reverse(empty.begin(), empty.end()); std::cout << "Sum: " << std::accumulate(empty.cbegin(), empty.cend(), 0) << std::endl; std::cout << empty.size(); } builds and runs as I expect: sum: 0 size: 0 Can I be guaranteed this behavior will happen on any standard-compliant compiler? Source: Windows ..

Read more

Let’s say I’ve got a txt file with mutiple line exemple: jeremy(thats the name) 0952966(thats the id) 5(nb of grades) 10 20 12 (grades) the question is how to isolated each things like the name the id and the grade into some attributes. When I read the file I can isolated some of the things ..

Read more