If i have a set of numbers:
48098, 50933, 3128, 323, 42, 5..etc
how can i convert them into integers? I have an example of a code (see below) that will convert one number, not the whole set. So, im having trouble trying to convert a set of numbers seperated by commas into integers.
PLEASE HELP!!!!!!
*NOTE - im reading a .txt file from wordpad using "fstream"
Here is the example of the code:
#include <sstream>
#include <string>
#include <iostream>
using namespace std;
bool StringToInt(const string &s, int &i);
int main(void)
{
string s1 = "12";
string s2 = "ZZZ";
int result;
if (StringToInt(s1, result))
{
cout << "The string value is " << s1
<< " and the int value is " << result << endl;
}
else
{
cout << "Number conversion failed" <<endl;
}
if (StringToInt(s2, result))
{
cout << "The string value is " << s2
<< " and the int value is " << result << endl;
}
else
{
cout << "Number conversion failed on " <<s2 <<endl;
}
return(0);
}
bool StringToInt(const string &s, int &i)
{
istringstream myStream(s);
if (myStream>>i)
return true;
else
return false;
}