我想寫稱爲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