C++fatal error C1004: unexpected end of file found错误求解

queen_sky 2016-06-08 01:51:38
代码不存在花括号少打情况
...全文
117 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
queen_sky 2016-06-08
  • 打赏
  • 举报
回复
THANKS
小灸舞 2016-06-08
  • 打赏
  • 举报
回复
你类里面的string Level(int score)这个函数最后少了一个大括号
queen_sky 2016-06-08
  • 打赏
  • 举报
回复
#include<iostream> #include<fstream> using namespace std; class Student{ public: int number; char name[10]; int score; string level; Student(int number,char name[],int score){ this->number=number; strcpy(this->name,name); this->score=score; } string Level(int score){ if(0<=score&&score<=100){ switch(score/10){ case 10:return "优";break; case 9:return "优";break; case 8:return "良好";break; case 7:return "中";break; case 6:return "及格";break; default:return "不及格";break; } } level=Level(score); char show(){ cout<<number<<name<<score<<endl; } }; /*istream & operator>>(istream & in,Student & stu){ in>>stu.number; in>>stu.name; in>>stu.score; in>>stu.level; return in; } ostream & operator<<(ostream & out,const Student & stu){ out<<stu.number; out<<stu.name; out<<stu.score; out<<stu.level; return out; }*/ int main(){ string level; Student student(3,"134",4); fstream f; f.open("file.txt",ios::out); cout<<"输入学生个数:"<<endl; int n; cin>>n; if(f.fail()) { cout << "打开文件失败!" << endl; exit(1); } cout<<"输入学生信息:"<<endl; for(int i=0;i<n;i++){ cin>>student.number>>student.name>>student.score; f<<student.number<<student.name<<student.score<<student.level; } f.close(); if(f.fail()) { cout << "打开文件失败!" << endl; exit(2); } f.open("file.txt",ios::in); Student stu(1,"2",0); f>>stu; cout<<stu<<endl; f<<stu.number<<stu.name<<stu.score<<stu.level; f.close(); system("PAUSE"); return 0; }
小灸舞 2016-06-08
  • 打赏
  • 举报
回复
上代码。
MSDN里对C1004的描述:https://msdn.microsoft.com/en-us/library/4exw7xyc.aspx

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧