So I am reading a file and trying to store the information into vectors and having trouble with it, I know I'm messing up somewhere but don't know how to fix it separating the spaces and storing the right information into the right vectors, please any help will be appreciated. The text file is arranged like this......
file.txt
Name Order-number Phone-number Date
----------------------------------------------------------------------------
Billy Chamber 1763829 555-7863 1/23
Bob Hurt 2143567 555-7234 3/23
Nurt Kille 7283495 555-8273 2/12
...............
...............
....
....
.....
int choice; // choice for the user to enter
string line, garbage1, garbage2;
const string space = " ";
ifstream file; // reading the file
company info; // called for use of struct
file.open("file.txt"); // file to be read
cin >> choice; // choice for user to enter
cout << "0: exit prog." << endl;
cout << "1: read from file " << endl;
cout << "2: add to file " << endl;
cout << "3: delete from file " << endl;
if (choice == 0) {
cout << "exiting the prog" << endl;
system("exit");
}
cout << "reading from the file" << endl;
if (file.is_open()) {
garbage1 = line; // tosses the first line no use
garbage2 = line; // tossess the ------ line
string contain;
// problem occurring here.....
while (getline(file, line)) {
if (line != space) {
line.substr(0, line.find(" "));
for (int i = 0; i < file.eof(); i++) {
info.Name[i] = line;
info.Order_num = line;
info.phone = line;
}
}
}
file.close(); // closing the file
}
else {
cout << "file cant be open" << endl;
}
......
......
......
while (getline(file, line)) {
if (line != " ") {
istringstream is(line);
for (int i = 0; i < file.eof(); i++) {
std::istringstream is(line);
string files_name, files_phone, files_date;
int files_order;
is >> files_name >> files_phone >> files_order >> files_date;
info.Name = files_name;
info.phone = files_phone;
info.Order_num = files_order;
info.date = files_date;
companies.push_back(company); // here is the error i have is expected //identifier why is that
}
}
}
the error i have is expected identifier doesnt it not get stored in the vector i thought puch back adds at the end of the vector