StringStream

Sort by

recency

|

548 Discussions

|

  • + 0 comments
    without using the sstream
    #include<iostream>
    #include<string>
    #include<vector>
    
    using namespace std;
    
    vector<int> pras(string str){
        vector<int> point;
        vector<int> point2;
        point.push_back(0);
        for(int i=0;i<str.length();i++){
            if(str.find(",",i)+1 == 0){
                break;
            }
            point.push_back(str.find(",",i)+1);
        }
    
        for(int i =0;i<point.size()-1;i++){
            if(point[i] != point[i+1]){
                point2.push_back(point[i]);
            }
        }
        point2.push_back(point[point.size()-1]);
    
        for(int i =0;i<point2.size()-1;i++){
            point[i] = stoi(str.substr(point2[i],point2[i+1]-point2[i]-1));
        }
        point[point2.size()-1] = stoi(str.substr(point2[point2.size()-1]));
    
        point.resize(point2.size());
    
        return point;
    }
    
    int main(){
        string str;
        cin>>str;
        vector<int> data = pras(str);
        for(int i =0; i<data.size();i++){
            cout<<data[i]<<endl;
        }
    
        return 0;
    }
    
  • + 0 comments

    Here is my code!

    #include <sstream>
    #include <vector>
    #include <iostream>
    using namespace std;
    
    vector<int> parseInts(string str) {
        stringstream mystring(str);
        vector<int> ints;
        char ch;
        int num;
        while (mystring >> num) {
            ints.push_back(num);
            mystring >> ch;
        }
        return 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;
    }
    
  • + 0 comments

    include include include include include include using namespace std; int main() { string n; cin>>n; stringstream ss(n); vector numbers; int num; char comma; while (ss >> num){ numbers.push_back(num); ss >> comma; } for (int i=0; i < numbers.size();i++){ cout<

  • + 0 comments

    using namespace std;

    int main() { string s; getline(cin,s); for(int i = 0; i

  • + 0 comments
    vector<int> parseInts(string str) {
        
        vector<int> arr;
        string t;
        stringstream ss(str);
        char del = ',';
        
        while (getline(ss, t, del)){
            int num = atoi(t.c_str());
            arr.push_back(num);
        }
        return arr;
    }