I'm playing around with stringstreams, and I've got a line like:
10 651.23 Some longer name
I'd like to fetch it into uint, double and string like 10, 651.23, "Some longer name"
So I've tried
iss >> quantity >> price >> std::noskipws >> name;
But it seems it isn't so easy as it looks. How can I get rest of the string including whitespaces?
Later I want to show the float with leading character and fixed precision:
std::cout << std::setprecision(2) << std::fixed << std::setw(7) << std::setfill('.') << price;
However when I use std::fixed, my fill and width get rejected. How to fix that?
Thanks
Current code:
std::string filename;
std::ifstream is;
do {
std::cout << "Podaj nazwę pliku do wczytania: " << std::endl;
std::cin >> filename;
is.open(filename.c_str());
if(is.good()) break;
} while(true);
std::string name;
std::string wtf;
unsigned int quantity = 0;
double price = 0;
unsigned int i = 1;
while(is >> quantity >> price >> std::ws && std::getline(is, name)) {
std::cout << "| ";
std::cout << std::setw(2) << i++ << " | ";
std::cout << std::setw(30) << std::setfill('.') << name << " | ";
std::cout << std::setw(3) << std::setfill(' ') << quantity << " x ";
std::cout << std::setprecision(2) << std::setw(10) << std::setfill(' ') << std::fixed << price << " zl | ";
std::cout << std::setw(11) << std::setfill(' ') << quantity * price << " zl |";
std::cout << std::endl;
}
The file looks like:
10 12999 TV55AA8000 smarttv ultra HD
5 12990 TV55AB600 smarttv ultraHD
20 9999 TV55GD2340s smarttv
10 7999 TV463400 funkcja 3D
20 1699.5 telewizor super!
30 1400 telewizor 3d 1000Hz
20 12999 telewizor nr 1
30 12000 EE55650 smarttv
10 1000 ED325400s
10 14350.00 EE80234
5 5600.00 TV60ED23231 smart tv plazma
10 2000.00 TV320323
1 12999.00 TV66EE231231 smarttv
12 3400.00 TV4243dss 3D