1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
std::ifstream in("Sales.csv");
std::string temp;
std::istringstream line;
line.exceptions(std::ios::fail);
std::tm datetime; //You should use your class members
double price, value; //Instead of these
while(std::getline(in, temp)) {
line.str(temp);
std::getline(line, temp, ','); //date
std::sscanf(temp.c_str(), "%d/%d/%d", &datetime.tm_mon, &datetime.tm_mday, &datetime.tm_year); //Or just parse it as a stream too
std::getline(line, temp, ','); //time
std::sscanf(temp.c_str(), "%d:%d", &datetime.tm_hour, &datetime.tm_min, );
std::getline(line, temp, ','); //price
price = std::stod(temp);
std::getline(line, temp, ','); //value
value= std::stod(temp);
}
|