
How do I get integers separated by a ', ' in C++ in a string?
Ex.
string=1, 2, 3;
//something to find the integers and put them in array a
cout<
output: 123

Hi Friend,
Try this:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str = "1,2,3";
string::iterator It = str.begin();
while ( It != str.end() )
{
if ( *It == ',' )
*It = ' ';
cout << *It++;
}
cout << endl;
return 0;
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.