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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
struct comp_info{
string compania;
string domicilio; // D=
string planta_m; // M= planta matriz
string gerente_p; // P= planta
string gerente_c; // C= compras
string gerente_rh; // R= recursos humanos
string gerente_m; // T= mantenimiento
int n_empleados; // E= number de
string insumo; // I= requerido
string giro; // G=
};
void Tokenize(const string& str,vector<string>& tokens,const string& delimiters = "") // via http://www.geocities.com/eric6930/cplus.html unknown author presumed Eric.
{
string::size_type lastPos = str.find_first_not_of(delimiters, 0);
string::size_type pos = str.find_first_of(delimiters, lastPos);
while (string::npos != pos || string::npos != lastPos)
{
tokens.push_back(str.substr(lastPos, pos - lastPos));
lastPos = str.find_first_not_of(delimiters, pos);
pos = str.find_first_of(delimiters, lastPos);
}
}
int _tmain(int argc, _TCHAR* argv[])
{
string file_n;
vector<comp_info> ci; // this is the vector where i want to store all the info for the companies
vector<string> tok;
vector<string> tf;
cout<<"Enter file to parse: ";
getline(cin,file_n);
cout<<endl<<"The file to parse is: "<<file_n<<endl;
ifstream file;
file.open(file_n.c_str(),ios::in);
string ch[2000];
if(file.is_open())
{
while(!file.eof())
{
getline(file,*ch);
tf.push_back(*ch);
}
}
else
{
cout<<"Wrong filename, enter correct filename"<<endl;
return 0;
}
file.close();
// input operations completed
// begin parsing
comp_info Ci;
for(int i=0;i<tf.size();i++)
{
tok.clear();
Tokenize(tf.at(i),tok,"=");
for(int a=0;a<tok.size();a++)
{
// right here is where i need the help
}
}
return 0;
}
|