79645758

Date: 2025-05-30 15:56:24
Score: 0.5
Natty:
Report link

Read comma Separated Integers Mini

#include <iostream>
#include <sstream>
#include <vector>
using namespace std;

int main() {
    string input;
    cout << "Enter comma separated integers: ";
    getline(cin, input);

    vector<int> numbers;
    stringstream ss(input);
    string token;

    while (getline(ss, token, ',')) {
        // Remove leading/trailing spaces if any
        size_t start = token.find_first_not_of(" \t");
        size_t end = token.find_last_not_of(" \t");
        if (start != string::npos && end != string::npos)
            token = token.substr(start, end - start + 1);

        // Convert to int and add to vector
        numbers.push_back(stoi(token));
    }

    // Print the numbers
    cout << "Numbers in the list: ";
    for (int num : numbers) {
        cout << num << " ";
    }
    cout << endl;

    return 0;
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: user30431451