本文介绍了请我的程序在最后因为我使用了fstream :: read()函数而崩溃,需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 请在系统(暂停)行之后在程序的最后编程崩溃。 我尝试过: #include< iostream> #include< fstream> #include< string> #include< vector> #include< iterator> using namespace std; void eatline(){while(cin.get()!='\ n')继续; } struct sal { string x; int y; }; void writedata(string& name,int x) { fstream file; file.open(info.dat,ios :: out | ios :: app | ios :: binary); if(file.is_open()) { sal l = { name, x }; file.write(reinterpret_cast< char *>(& l),sizeof(l)); file.close(); } } void red(vector< sal>& p) { vector< sal> :: iterator r = p.begin(); for(r = p.begin(); r!= p.end(); r ++) cout<< (* r).x<< << (* r).y<< ENDL; } int main() {长想法; string name1; cout<< 输入瞳孔的名称<< ENDL; while(getline(cin,name1)&& name1 [0]!='\ 0') { cout<< 输入支付的学费金额; cin>>理念; eatline(); writedata(name1,idea); cout<< 输入下一个学生的名字(按回车键退出)\ n<< ENDL; } cout<< 这些是你输入的学生的名字和学校的名字; ifstream fin; fin.open(info.dat,ios :: in | ios :: binary); sal k; vector< sal> j; while(fin.read(reinterpret_cast< char *>(& k),sizeof k)) { j.push_back(k); } fin.close(); red(j); system(暂停); 返回0; } 解决方案 please program crashes at the very end of my program after the system("pause") line.What I have tried:#include<iostream>#include<fstream>#include<string>#include<vector>#include<iterator>using namespace std;void eatline() { while(cin.get()!= '\n')continue;} struct sal {string x;int y; };void writedata(string & name, int x){ fstream file; file.open("info.dat", ios::out | ios::app | ios::binary);if (file.is_open()){sal l = {name,x};file.write(reinterpret_cast<char *>(&l), sizeof(l));file.close();}}void red(vector<sal> & p){vector<sal>::iterator r = p.begin();for (r=p.begin();r!=p.end();r++)cout << (*r).x << " " << (*r).y << endl;}int main(){long idea;string name1;cout << "Enter the name of the pupil" << endl;while (getline(cin, name1) && name1[0]!='\0'){cout << "Enter the amount of school fees paid\n";cin >> idea;eatline();writedata(name1, idea);cout << "Enter the name of the next pupil(press enter to quit)\n" << endl;}cout << "These are the names and school fess of the pupils you entered\n";ifstream fin;fin.open("info.dat",ios::in|ios::binary);sal k;vector<sal>j;while (fin.read(reinterpret_cast<char *>(&k), sizeof k)){j.push_back(k);}fin.close();red(j);system("pause");return 0;} 解决方案 这篇关于请我的程序在最后因为我使用了fstream :: read()函数而崩溃,需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 11-01 16:48