[SOLVED] See my answer below.
I am trying to use stringstream (named ss) to convert some strings to ints and some to double and such, but the values are all coming out wrong. I have a vector of strings named vec, initialized like this:
[0] = ID # in hex
[1] = phone number
[2] = last name
[3] = first name
[4] = sales number
[5] = percent of sales
Now I go through the vector and put the values into int, string, or double:
std::string lname, fname, pnum;
int ID;
double sales, percent;
if(vec.size()!=6) {
//throw exception
}
else {
ss<<std::hex<<vec[0];
ss>>ID;
pnum = vec[1];
lname = vec[2];
fname = vec[3];
ss<<vec[4];
ss>>sales;
ss<<vec[5];
ss>>percent;
}
but the output looks like this for every customer. What are my ints always 1 and my doubles always this weird number?
Customer made: Langler Tyson 1 7667230284 2.12303e-314 2.12201e-314
You will need to introduce a separator between the numbers to be ablew to extract them out:
Besides this, you need to revert back to the original decimal format after extracting the ID:
Also, because you use the same
ssstream to extract the vector elements, the state of the stream is in error after the last vector element is extracted. You need to clear the error state before further insertion/extraction. Using a new stream will solve the problem as well: