Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // https://www.geeksforgeeks.org/tokenizing-a-string-cpp/
- #include<bits/stdc++.h>
- using namespace std;
- string str,x;
- vector<string>tokens;
- int string_to_int(string now)
- {
- int ret=0,i;
- for(i=0;i<now.size();i++){
- ret=(ret*10+(now[i]-'0'));
- }
- return ret;
- }
- int main()
- {
- freopen("input.txt","r",stdin);
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int i,j;
- cin>>str;
- stringstream ss(str);
- while(getline(ss,x,',')){
- tokens.push_back(x);
- }
- for(auto xx : tokens)cout<<xx<<endl;
- cout<<"============"<<endl;
- for(i=1;i<tokens.size();i+=2){
- int now=string_to_int(tokens[i]);
- cout<<now<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement