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.
Hint please - I am stuck on determining the size of the string. As you can see from my code below I am not sure how many numbers I am parsing. Is there a way for me to know how many numbers are in str? First I thought that it was simply half of the length ("23,4,56") this would be a length of 7/2=3 however this will not generalize well since if it were ("1,2,3") this would be 5/2=2 which is wrong. Any suggestions?
vector<int> parseInts(string Str) {
vector<int> result;
stringstream str(Str);
char ch;
int temp;
for(int i = 0; i < HERE; i++){
str >> temp >> ch;
result.push_back(temp);
}
return result;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
StringStream
You are viewing a single comment's thread. Return to all comments →
Hint please - I am stuck on determining the size of the string. As you can see from my code below I am not sure how many numbers I am parsing. Is there a way for me to know how many numbers are in str? First I thought that it was simply half of the length ("23,4,56") this would be a length of 7/2=3 however this will not generalize well since if it were ("1,2,3") this would be 5/2=2 which is wrong. Any suggestions?