-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringStream.cpp
More file actions
34 lines (28 loc) · 874 Bytes
/
StringStream.cpp
File metadata and controls
34 lines (28 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <sstream>
#include <vector>
#include<string>
#include <iostream>
using namespace std;
vector<int> parseInts(string str) {
vector<int> vec; // Declares a vector to store the ints
stringstream ss(str); // Declares a stringstream object to deal with the
// modification of the string
char ch;
int temp;
while (ss) // While the stringstream object does not hit a null byte
{
ss >> temp >> ch; // Extract the comma seperated ints with the extraction
// >> operator
vec.push_back(temp); // Push the int onto the vector
}
return vec; // Return the vector of ints
}
int main() {
string str;
cin >> str;
vector<int> integers = parseInts(str);
for(int i = 0; i < integers.size(); i++) {
cout << integers[i] << "\n";
}
return 0;
}