Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <algorithm>
- #include <vector>
- using namespace std;
- int main () {
- // Initializing variables and vectors
- size_t pos;
- string last_name;
- string first_name;
- string number{};
- string full_name{};
- string line{};
- ifstream myfile ("employees.dat");
- vector<string > number_vector;
- vector<string> last_name_vector;
- vector<string> first_name_vector;
- // Reading File Contents:
- if (myfile.is_open())
- {
- while ( myfile.good() )
- {
- getline (myfile,line);
- // Extracting Numbers from Lines
- for (size_t i {0}; i < line.length(); ++i){
- if (line[i] == '#'){
- line.clear();
- }
- else if (isdigit (line[i]))
- number += line[i];
- // Extracting Full Name
- else if (isalpha(line[i]) || line[i] == ' ')
- full_name += line[i];
- }
- number_vector.push_back(full_name);
- cout<< (number_vector[0]);
- }
- myfile.close();
- }
- else cout << "Unable to open file"<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement