StringStream

Sort by

recency

|

509 Discussions

|

  • + 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;
    

    }

  • + 0 comments

    vector parseInts(string str) { vector vec; stringstream ss; ss << str; char ch; int num; while (!ss.eof()){ ss >> num >> ch; vec.push_back(num); } return vec; }

  • + 0 comments

    stringstream ss; vector temp; int tempstr; ss << str; char ch; while (!ss.eof()) {

        ss >> tempstr>>ch;
        temp.push_back(tempstr);
    

    } return temp;

  • + 0 comments
    {
        vector<int> tokens;
        stringstream ss(str); 
        string token;
        char delimeter = ',';
        while (getline(ss, token, delimeter)) { 
            tokens.push_back(stoi(token)); 
        } 
        return tokens;
    }