I'm trying to find the simplest way to convert a string array of numbers to an int array so that I can use it in calculations. Stringstream and stoi have so far both crashed the program or not worked. Any help? Thanks!
int counter = 0;
string nums[51];
while (! rel.eof())
{
getline(rel, tuple);
cout<<tuple<<endl;
//minituple[counter] = tuple.substr(0,4);
//counter++;
istringstream iss(tuple);
do
{
string found_num;
iss >> found_num;
if (iss.fail())
break;
char goaway;
goaway = found_num.at(0);
if (goaway == '\n')
counter--;
else if (goaway == ' ')
counter--;
{
nums[counter] = found_num;
cout << "Substring: " << found_num << endl;
}
counter++;
} while (iss);
}
int int_nums[51];
for (int i = 0; i <= 51; i++)
{
if (!nums[i].empty())
{
stoi(nums[i]);
}
}