Cześć, niedawno postanowiłem się sprawdzić i napisać quiz z 2 odc. obiektowego c++, tylko bez patrzenia na odcinek oraz używając Visual Studio. Wszystko jest Ok, do momentu odczytu z pliku. Sprawdziłem to z filmem i zrobiłem dokładnie tak samo. Pomimo tego dostaję następujące błędy:
'file' uses undefined class 'std::basic_fstream<char,std::char_traits<char>>',
left of '.open' must have class/struct/union,
left of '.close' must have class/struct/union,
left of '.good' must have class/struct/union,
'getline': identifier not found .
Mój kod wygląda tak:
fstream file;
file.open(path, ios::in);
if (file.good() == false)
{
cout << "An error occurred while opening the file!";
system("pause > nul");
exit(0);
}
else {
int startFrom = (queNum - 1) * 6 + 1;
int lineNum = 1;
string line;
while (getline(file, line))
{
if (lineNum == startFrom) que = line;
if (lineNum == startFrom + 1) ansA = line;
if (lineNum == startFrom + 2) ansB = line;
if (lineNum == startFrom + 3) ansC = line;
if (lineNum == startFrom + 4) ansD = line;;
if (lineNum == startFrom + 5) correct = line[0];
lineNum++;
}
file.close();
}
Kiedy poszukałem w internecie o co chodzi, to wskazywali na bark lub błąd przy dodawaniu bibliotek. U mnie chyba jest OK:
#include <iostream>;
#include <fstream>;
#include <cstdlib>;
#include <string>;
#include "stdafx.h";
#include "Question.h";