我正在尝试使我的Outfile流成为全局文件,但 pop 的结果是“'outfile'未命名类型”错误。我试着做一些谷歌搜索,但都没有与fstream ..
我的代码:
#include<iostream>
#include<string>
#include<iomanip>
#include<fstream>
#include<cstdlib>
using namespace std;
void determinepointer(string[],int,float[]);
void printresults(string[],float[],int,char[][9],int[]);
float calcGPA(float[],int[],int);
ofstream outfile;
outfile.open("StudentsTranscript.txt");//the problematic part
int main()
{
ifstream infile;
int coursenum;
infile.open("StudentsFile.txt");
infile.ignore(40,'\t');
infile>>coursenum;
char coursecode[coursenum][9];
int credithr[coursenum];
infile.ignore(13);
for (int i =0;i<coursenum;i++)
{
infile>>coursecode[i];
infile.ignore(1);
if(coursecode[i][7]=='1')
credithr[i]=1;
else if(coursecode[i][7]=='2')
credithr[i]=2;
else if(coursecode[i][7]=='3')
credithr[i]=3;
else if(coursecode[i][7]=='4')
credithr[i]=4;
else
{
cout<<"invalid course code, please re-check & run this program again";
exit(0);
}
}
infile.ignore(10,'\t');
outfile<<"STUDENT'S INDIVIDUAL TRANSCRIPT\n\n";
while(!infile.eof())
{
char name[40];
string grade[coursenum];
float coursepointer[coursenum];
infile.getline(name,40,'\t');
outfile<<name<<endl;
for (int i =0;i<coursenum;i++)
{
infile>>grade[i];
infile.ignore(2);
}
determinepointer(grade,coursenum,coursepointer);
printresults(grade,coursepointer,coursenum,coursecode,credithr);
}
infile.close();
cout<<"done";
return 0;
}
**编码太长,完整代码在这里:https://drive.google.com/file/d/0B_ir83gzFmIBQ0dXaGhPNXBJZkE/view?usp=sharing
最佳答案
发表声明
outfile.open("StudentsTranscript.txt");//the problematic part
内部的主要功能。您只能在函数外部声明变量,而不使用它。
关于c++ - fstream 'outfile'没有命名类型,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34252314/