I am trying to separate a list of numbers such as: 34,45,12.3,100,34.6,50
I can do it only if there are no decimals like this:
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
int main()
{
std::string str = "34,45,12.3,100,34.6,50";
std::vector<int> vect;
std::stringstream ss(str);
int i;
while (ss >> i)
{
vect.push_back(i);
if (ss.peek() == ',')
ss.ignore();
}
for (i=0; i< vect.size(); i++)
std::cout << vect.at(i)<<std::endl;
}
The problem here is with the decimals. The above will produce:
34 45 12 3 100 34 6 50
while it should produce:
34 45 12.3 100 34.6 50
basically the above code when it sees a dot '.'
it acts as if it was a comma.
Any ideas?