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
|
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
const char *const Buf = "carlsum1, 22674, Carl Sum 1, 4115, 1, 65--84279319, 65--67353779, , , , 11311, 1" "\n"
"carlsum2, 22674, Carl Sum 2, 4115, 1, 65--84279319, 65--67353779, , , , 11311, 1" "\n"
"carlsum3, 22674, Carl Sum 3, 4115, 1, 65--84279319, 65--67353779, , , , 11311, 1" "\n"
"carlsum4, 22674, Carl Sum 4, 4115, 1, 65--84279319, 65--67353779, , , , 11311, 1";
int main()
{
stringstream complete_stream(Buf);
vector<vector<string> > arrCompany;
string line;
for(int lineCount = 0; getline(complete_stream, line); ++lineCount)
{
if(lineCount>2)
{
cout << "Line: " << line.c_str() << endl;
stringstream line_stream(line);
vector<string> line_part_vector;
string line_part;
for(int itemNo=0; getline(line_stream, line_part,','); ++itemNo)
{
if(itemNo==0||itemNo==5||itemNo==6)
{
cout << "Line part " << itemNo << ": " << line_part.c_str() << endl;
line_part_vector.push_back(line_part);
}
}
arrCompany.push_back(line_part_vector);
}
}
return 0;
}
| |