Read from file until a specific character is detected
Hello, simply question, how do i alter my cin fstream function so it stops reading until a specific character (in my case ',") is detected?
Here is an example of my file output im reading from:
|
N,1234,box,123.45,1,1,kg,5
|
here is my method where im reading from the file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
fstream& AmaProduct::load(std::fstream& file){
char sku2[25];
char name2[25];
double price2;
int taxed2;
int quantity2;
int qtyneed2;
file.getline(sku2, 25, ',');
sku(sku2);
// -----------------------------
file.getline(name2, 25, ',');
name(name2);
// -----------------------------
file << fixed;
file << setprecision(2);
file >> price2;
price(price2);
file.ignore(1);
// -----------------------------
file >> taxed2;
taxed(taxed2);
if (taxed2 == '1'){
taxed3 = false;
}
else if (taxed2 == '0') {
taxed3 = true;
}
file.ignore(1);
// -----------------------------
file >> quantity2;
quantity(quantity2);
file.ignore(1);
// -----------------------------
file >> unit_;
unit(unit_);
file.ignore(1);
// -----------------------------
file >> qtyneed2;
qtyNeeded(qtyneed2);
return file;
}
|
its specific to my unit reading.. it reads kg,5 instead of simply just kg
Whats the fix for this?
For reading unit_
you need getline() again (like for sku2/name2).
Topic archived. No new replies allowed.