gpt4 book ai didi

c++ - fstream 'outfile' 没有命名类型

转载 作者:行者123 更新时间:2023-11-30 03:46:09 24 4
gpt4 key购买 nike

我正在尝试使我的输出文件流成为全局流,但最终弹出“‘输出文件’未命名类型”错误。我试过做一些谷歌搜索,但没有一个与 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com