Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#include<iostream>
#include <fstream>
#include <vector>
#include <sstream>
#include <string>
// followed the following guide https://www.youtube.com/watch?v=PBqWb5VI2L8
std::vector<std::string> read_record_from_file(std::string file_name, std::string search_term) {
std::vector<std::string> record;
std::ifstream file;
file.open(file_name);
bool found_record = false;
std::string field_one;
std::string field_two;
std::string field_three;
std::string field_four;
std::string field_five;
std::string field_six;
std::string field_seven;
std::string field_eight;
std::string field_nine;
std::string field_ten;
std::string field_eleven;
std::string field_twelve;
while (getline(file, field_one, ',') && !found_record) {
getline(file, field_two, ',');
getline(file, field_three, ',');
getline(file, field_four, ',');
getline(file, field_five, ',');
getline(file, field_six, ',');
getline(file, field_seven, ',');
getline(file, field_eight, ',');
getline(file, field_nine, ',');
getline(file, field_ten, ',');
getline(file, field_eleven, ',');
getline(file, field_twelve, '\n');
if (field_one == search_term) {
record.push_back(field_one);
record.push_back(field_two);
record.push_back(field_three);
record.push_back(field_four);
record.push_back(field_five);
record.push_back(field_six);
record.push_back(field_seven);
record.push_back(field_eight);
record.push_back(field_nine);
record.push_back(field_ten);
record.push_back(field_eleven);
record.push_back(field_twelve);
found_record = true;
}
}
return record;
}