#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include <cstdio>
usingnamespace std;
int main()
{
ifstream fin("SMX_Test.csv");
if (!fin)
{
perror (nullptr);
return errno;
}
vector<vector<string>> SM_Invoice;
string line;
while (getline(fin, line)) // for each line in input
{
// create tempory vector to store the items
vector<string> items;
// read all data with the stringstream and add to temp vector
istringstream iss(line);
string tmp;
while(iss >> tmp) // extract data and store in items
items.push_back(tmp);
SM_Invoice.push_back(items); // finally add items to invoice
}
// just to test if we read all data correctly
for (constauto& v: SM_Invoice)
{
for (constauto& s: v)
cout << s << "\t";
cout << "\n";
}
}
Tested with input file:
Anna 2 Hammer
Lisa 3 Knifes
Debbie 5 Spoons