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