-3
왜 줄 수가 항상 0입니까? 그것은 10이어야하지만 출력은 항상 0입니다. 그 방법에 문제가 있습니까? while(!inputFile.eof())
와줄 수는 항상 0입니다.
int main() {
vector<double> doubleCoefficient; // vector to store unknown number of equations (double)
/* Read from file and assign values to vector */
//File stream object
ifstream inputFile;
//Open the txt file
inputFile.open("test.txt");
//search for the text file
if(!inputFile.is_open())
{
cerr << "Error opening file \n";
exit(EXIT_FAILURE);
}
else
{
cout << "File found and successfully opened. \n";
}
double x;
while(!inputFile.eof()){
inputFile >> x;
doubleCoefficient.push_back(x);
}
int count =0;
string line;
while (getline(inputFile, line)){
count++;
}
cout << "Number of lines in text file:" << count << endl;
inputFile.close();
}
왜냐하면 당신은 file_의 끝에서부터 카운트하기 시작했기 때문에, 당신은 아무 것도 세지 않을 것입니다. – gkovacs90
@ user3504305 pls 확인 업데이트 – gkovacs90