SHARE
TWEET

Untitled

a guest Feb 21st, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.     #include <fstream>
  3.     #include <string>
  4.     #include <algorithm>
  5.     #include <vector>
  6.     using namespace std;
  7.   int main () {
  8.       // Initializing variables and vectors
  9.       size_t pos;
  10.       string last_name;
  11.       string first_name;
  12.       string number{};
  13.       string full_name{};
  14.       string line{};
  15.       ifstream myfile ("employees.dat");
  16.       vector<string > number_vector;
  17.       vector<string> last_name_vector;
  18.       vector<string> first_name_vector;
  19.  
  20.       // Reading File Contents:
  21.       if (myfile.is_open())
  22.       {
  23.         while ( myfile.good() )
  24.         {
  25.           getline (myfile,line);
  26.  
  27.            // Extracting Numbers from Lines
  28.             for (size_t i {0}; i < line.length(); ++i){
  29.              if (line[i] == '#'){
  30.                  line.clear();
  31.              }
  32.  
  33.              else if (isdigit (line[i]))
  34.                  number += line[i];
  35.              // Extracting Full Name
  36.  
  37.              else if (isalpha(line[i])  || line[i] == ' ')
  38.                  full_name += line[i];
  39.  
  40.  
  41.          }
  42.  
  43.           number_vector.push_back(full_name);
  44.          cout<< (number_vector[0]);
  45.  
  46.         }              
  47.  
  48.         myfile.close();
  49.       }
  50.              else cout << "Unable to open file"<<endl;
  51.  
  52.       return 0;
  53.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top