CamolaZ

Read client

Apr 21st, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. void readClient(Client &client, ifstream &cli, vector <Client> &clients, int &clientID)
  2. {
  3.        
  4.     if (cli.is_open())
  5.     {
  6.  
  7.         string line;
  8.         int counter = 1;
  9.         stringstream ss; // There ss have value.. "" see
  10.         /*getline(cli, line, '\0');
  11.         cout << "FileCli:\n" << line <<  endl; erase of file..*/
  12.         while (getline(cli, line,'\n'))
  13.         {
  14.             cout << "line cliA: "<< line << endl; // the content of 1º statment (until first '\n', 1º line of client  is showed
  15.             ss.str(line);
  16.             string s2 = ss.str();
  17.             cout << "cliD: " << s2 << endl;
  18.  
  19.             while (getline(ss, line, ';')) // or a condition !trasactions.eof()
  20.             {
  21.                 trimSpaces(line);
  22.                 cout << "line cliB: " << line << '\t' << endl;//-" << line; << "-" << endl; // the content until first ',' is showed
  23.                 //  string s = ss.str(); cout << s;  s = ss.str("Bom dia!"); cout << s; s = ss.str("\n"); cout << s;
  24.                 //ss.str(line); // not altered nothing ... on line!!
  25.                 string s = ss.str();
  26.                 cout << "cliC: "<< s<<endl;
  27.                 switch (counter)
  28.                 {
  29.                 case 1: // save id of client
  30.                     client.id = stoi(line) ; //cli
  31.                     if (client.id > clientID) // ss
  32.                         clientID = client.id; //faço  this mean that idMax is actualized cout << ss;
  33.                     counter++;
  34.                     ss.ignore(1, ';');
  35.                     /*ss.empty();
  36.                     ss.clear();*/
  37.                     break;
  38.                 case 2: // save name of client
  39.                 {
  40.                     client.name = line;
  41.                     counter++;
  42.                     ss.ignore(1, ';');
  43.                     break;
  44.                 }
  45.                 case 3: // save money spend by client
  46.                 {
  47.                     ss >> client.moneySpent;
  48.  
  49.                     counter = 1;
  50.                     clients.push_back(client); // put the info, save in struct as element of the vector
  51.                     ss.clear();
  52.                     cout << "Tamanho = " << clients.size() << endl;
  53.                     //cin << cli.
  54.                 }
  55.             //case 3: ss >>
  56.             }
  57.             }
  58.         }
  59.    
  60.     }
  61.     else
  62.         cerr << "error to open clients file" << endl; // with this output fuction,it can show the message with red colour
  63. }
Add Comment
Please, Sign In to add comment