Reading user input series of integers separated by comma

Hello, I'm new to C++ and I'm having trouble reading user input series of numbers separated by comma. I've been looking everywhere, but all I could find was how to read from an existing file. I actually don't know how to properly use getline to write user input to my array. Could anyone help me, please? Thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
using std :: cout;
using std :: cin;
using std :: endl;
#include <string>
using std :: string;
using std :: getline;

int main()
{
    int size;
    cout<<"How many numbers would you like to type? ";
    cin>>size;
    string str;
    int * foo;
    foo = new (std::nothrow) int [size];
    if(foo == nullptr)
        cout<< "Error: memory couldn't be allocated";
    else
    {
        cout<<"Enter number separated by comma(,)";
        //I'm supposed to read a series of comma delimited integers here and 
        //write them to my array, but I do not know how to do it
    }
    return 0;
}
Last edited on
Topic archived. No new replies allowed.