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;
}