我正在嘗試讀取具有多列的文件,以輸出收入超過$ 100,000和GPA小於或等於2.3的所有結果。我無法弄清楚哪種方法是正確的。文件輸出甚至不出現在終端上。請讓我知道是否需要更多細節。這裏是FILE。C++簡單多列文件讀取
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream inputFile;
char *student = new char[];
int salary=100000,
grades=2.3;
inputFile.open("Students.txt");
if(inputFile.fail()==1)
{
cout<<"File opening failed";
}
else
{
while(!inputFile.eof())
{
inputFile>>student;
}
inputFile.close();
}
int income=student[0];
int gpa=student[0];
for(int i=0;i!=inputFile.eof();i++)
{
income=student[i];
gpa=student[i];
if(income>=salary && gpa<=grades)
{
cout<<" "<<income<<" "<<gpa<<endl;
}
}
cin.get();
cin.get();
return 0;
}
首先,'字符*學生=新的char []'沒有意義 - 你需要在括號內指定的大小。 – 2013-05-04 01:52:54
啊,他是從.... J/K總裁 http://stackoverflow.com/questions/8723224/using-sscanf-to-parse-a-string – 2013-05-04 01:55:35
你覺得這樣做? 'for(int i = 0; i!= inputFile.eof(); i ++) '?提示:這是無意義的(但會編譯)。 – 2013-05-04 01:55:51