We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
vector<int>parseInts(stringstr){std::string::size_typesz;// alias of size_tvector<int>v;intn,coma;while(str.size()){n=stoi(str,&sz);v.push_back(n);coma=str.find(',');if(coma!=str.npos)str.erase(0,coma+1);elsestr.erase(str.begin(),str.end());}returnv;}
I think this problem can be thought of in different ways but in essence a casting to vector must be returned from an input string.
This code does the casting but eliminates the string as the vector stores an int. Therefore when it leaves the scope of the function the string destructor will not have to do any work.
StringStream
You are viewing a single comment's thread. Return to all comments →
Here is my code in C++:
I think this problem can be thought of in different ways but in essence a casting to vector must be returned from an input string.
This code does the casting but eliminates the string as the vector stores an int. Therefore when it leaves the scope of the function the string destructor will not have to do any work.