My task is to read this data from a file into a vector:
21000 Landhau Nolte brown
19000 Modern_fit Hoeffner magnolie
14700 Pure_Style Wellmann black
This is my attempt, but push back isn't working. I already looked at some examples here at Stack Overflow, but somehow it's not working.
functions.h
:
#pragma once
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
struct Kitchen {
double price;
string name;
string manufacturer;
string color;
};
main.cpp
:
#include "functions.h"
int main(){
vector<Kitchen> Kitchens;
fstream myFile;
myFile.open("kitchen.txt", ios::in);
if (myFile.is_open()) {
while (!myFile.eof()) {
double price;
string name;
string manufacturer;
string color;
myFile >> price >> name >> manufacturer >> color;
Kitchens.push_back(price, name, manufacturer, color);
}
myFile.close();
}
else cout << "not opened." << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
What am I doing wrong?