我想写称为student.h
一个C++的类定义将用户定义的输入文件读取的档次,档次写入由定义的输出文件 用户。这是我迄今为止,但我得到这个错误,我不知道如何解决它。我在想,如果有人可以帮助我解决这个问题:会员必须有类/结构/联合
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <fstream>
using namespace std;
class student {
private:
int id;
int n; // no of- grades
int A[200]; // array to hold the grades
public:
student(void); // constructor
void READ(void); // to read from a file to be prompted by user;
void PRINT(void); // to write into an output file
void showStudent(); //show the three attributes
void REVERSE_PRINT(void); // to write into output file in reverse order;
double GPA(void); // interface to get the GPA
double FAIL_NUMBER(void); //interface to get the number of fails
};
void student::READ()
{
ifstream inFile;
ofstream outFile;
string fileName;
cout << "Input the name of your file" << endl;
cin >> fileName;
inFile.open(fileName.c_str());
if (inFile.fail()) {
cout << fileName << "does not exist!" << endl;
}
else
{
int x;
inFile >> x;
while (inFile.good())
{
for(int i=0;i<200;i++)
{
A[i]=x;
}
inFile >> x;
}
inFile.close();
}
}
int main()
{
student a();
a.READ(); //Line 56
}
这是我得到的语法,当我编译代码:
1>------ Build started: Project: New Project, Configuration: Debug Win32 ------
1> Main.cpp
1>c:\users\randy\documents\visual studio 2012\projects\new project\new project\main.cpp(56): error C2228: left of '.READ' must have class/struct/union
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
'学生一();' - 删除(),它应该只是'学生答;' –
你不需要'(无效)'遍铺 –
这是一个有点不寻常具有像READ()这样的大写方法名称。你也从来没有设置学生的ID或成绩的数量。 – jarmod