Я создаю программу, которая будет иметь некоторые функции для работы с моей структурой. Я еще не добавил функции, но у меня проблемы с вводом / выводом файла. Мне нужно работать как с консолью, так и с файлом (зависит от выбора пользователя), поэтому я сделал создание / закрытие файлов в конструкциях switch-case (поскольку переменная 'choice' не меняется, если файл был открыт, он наверняка будет закрыт ). Но я получаю странную ошибку в XCode на myfile.close (): базовый тип ссылки на элемент 'FILE * ()' (он же _sFILE * () ') не является структурой или объединением.
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
#define MARK_AMOUNT 4
struct student{
string name;
string group;
int mark[MARK_AMOUNT];
};
istream& operator >> (istream& in, student& student) {
in >> student.name >> student.group;
for (int i = 0; i < MARK_AMOUNT; i++) in >> student.mark[i];
return in;
}
ostream& operator << (ostream& out, const student& student) {
out << student.name << "\t" << student.group << "\t";
for (int i = 0; i < MARK_AMOUNT; i++) out << student.mark[i] << " ";
return out;
}
int main(){
vector <student> list;
int choice, choice2;
cout << "Input:\n1 to work with files\n2 to work in console\n";
cin >> choice;
cout << "Input function number[1-3]: ";
cin >> choice2;
switch (choice) {
case 1:
{
string fileName;
cout << "Input name of file: ";
cin >> fileName;
ifstream myfile(fileName);
student temp;
while(!myfile.eof()){
myfile >> temp;
list.push_back(temp);
}
}
break;
case 2:
break;
default:
break;
}
switch (choice2) {
case 1:
break;
case 2:
break;
case 3:
break;
default:
break;
}
switch (choice) {
case 1:
{
myfile.close();
break;
}
case 2:
break;
default:
break;
}
return 0;
}