Sep 20, 2017 at 12:32pm
Well, you aren't outputting c_id on line 16, so there won't be a 1.
The rest of the string is going into c_last (as there are no whitespaces, but it's the only way you are going to retain commas).
Then c_discount and w_tax don't get any new values, so they stay as 0 and get output as such.
Try:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include <algorithm>
#include <string>
#include <iostream>
#include <sstream>
int main() {
int c_id{0};
std::string c_last;
double c_discount{0.0};
float w_tax{0.0};
std::stringstream data {"1 zzz 0.09 10.0"}; // <===== use spaces, not commas
data >> c_id >> c_last >> c_discount >> w_tax;
std::cout << c_id << " " << c_last << " " << c_discount << " "<< w_tax << "\n"; // <=== output c_id as well
return 0;
}
|
Last edited on Sep 20, 2017 at 12:48pm