StringStream

Sort by

recency

|

512 Discussions

|

  • + 0 comments

    My C++ code 😎🐦‍🔥

    #include <sstream>
    #include <vector>
    #include <iostream>
    using namespace std;
    
    vector<int> parseInts(string str) {
    	// Complete this function
        vector <int> result;
        stringstream ss(str);
        char ch;
        int temp;
        
        while(ss >> temp){
            result.push_back(temp);
            ss >> ch;
        }
        
        return result;
    }
    
    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
     vector<int> res;
        stringstream ss(str);
        int num;
        char comma;
        while(ss>>num)
        {
            res.push_back(num);
            ss>>comma;
        }
        return res;
    
  • + 0 comments

    int main() { string str; getline(cin,str);

    for(int i=0;i<str.length();i++)
    {
        if(str[i]==',')
        {
           cout<<"\n";
        }else
        {
            cout<<str[i];
        }
    

    } return 0; }

    //I hope this is helpful for beginners:)

  • + 0 comments

    include

    include

    include

    using namespace std;

    vector parseInts(string str) { stringstream ss(str); char ch; int a; vector result; int count = 1; for(int i =0; i < str.length(); i ++) { if (str[i] == ',') { count++; } }

    for(int i =0; i <count; i ++)
    {
        ss >> a >> ch ;        
        result.push_back(a);
    }
    
    return result;
    

    }

  • + 0 comments

    include

    include

    include

    include

    include

    include

    using namespace std; int main() {

    string input{};
    cin >> input;
    stringstream ss(input);
    
    vector<int> nums{};
    int n{};
    char bin{};
    int check{};
    if (!((ss.peek() - 48 > -1 && ss.peek() - 48 < 10) || ss.peek() == 45)) {
        ss >> bin;
    }
    while ((ss.peek() - 48 > -1 && ss.peek() - 48 < 10) || ss.peek() == 45)
    {
        check = ss.peek() - 48;
        if((check > -1 && check < 10)|| check == -3){
            ss >> n;
            nums.push_back(n);
        }
    
        ss >> bin;
    }
    
    for (int n : nums)
    {
        cout << n << '\n';
    }
    return 0;
    

    }