So the goal is to read a line from a file that looks like this
N,1234,box,kg,1,123.45,1,5
each data type is separated by a ',' all I need to do is to split it.
For example the first would be char = N.
Seconds would be int = 1234 and so on...
std::fstream& Product::load(std::fstream& file) {
char sku_[max_sku_length + 1];
char name[max_name_length + 1];
char unit[max_unit_length + 1];
double price_;
char taxed_, type, skip;
int quantity, qtyNeeded;
file >> type >> skip;
file >> sku_ >> skip;
file >> name >> skip;
file >> unit >> skip;
file >> taxed_ >> skip;
file >> price_ >> skip;
file >> quantity >> skip;
file >> qtyNeeded >> skip;
Product tmpObj(sku_, name, unit, quantity, taxed_ != 0, price_, qtyNeeded);
tmpObj.type_ = type;
*this = tmpObj;
return file;
}
This is my current function that I have for this. The problem I have is that it doesn't split off at the comma and instead will write it so my char arrays look like "g,1,123.4"