问题描述
- c++课设 车辆管理系统出错,求高人指教
-
请前辈指点,头痛啊!!!!!!!!两个主要函数
void struck::read(){
fstream struckfile("struck.txt",ios::in|ios::out);
vector vec(9);fun_substr(struckfile," " ,vec);
int i,j;
for(i=0,j=0;i<vec.size();i=i+9,j++){//vec.size实际使用大小c3[j].num = vec[i]; c3[j].id = vec[i+1]; c3[j].company= vec[i+2]; c3[j].km = atoi(vec[i+3].c_str()); c3[j].oil = stoi(vec[i+4].c_str()); c3[j].cost= stoi(vec[i+5].c_str()); c3[j].road = stoi(vec[i+6].c_str()); c3[j].all_cost =stoi( vec[i+7].c_str()); c3[j].kg = stoi(vec[i+8].c_str());
}
count_struck = j+1;
struckfile.close();
}void fun_substr(fstream &file,string str_sep ,vector &vec){
int count =0; string str = ""; string str_temp = ""; int pos = 0; int sep_len = str_sep.length(); int i=0; while(getline(file,str)){ pos = str.find(str_sep); vec.push_back(str.substr(0,pos)); str_temp = str.substr(pos+1,str.length()-pos-sep_len); pos = str_temp.find(str_sep); while(str_temp.compare("")&& (pos!=-1)){ i++; vec.push_back(str_temp.substr(0,pos)); str_temp = str_temp.substr(pos+1,str_temp.length()-pos-sep_len); pos = str_temp.find(str_sep); } vec.push_back(str_temp); }
}
这里是源代码及课设要求,麻烦大家了,谢谢了。
真不好意思,还要大家下载查看。
http://pan.baidu.com/s/1dD0HPst
解决方案
目测,c3[j]这个没有分配内存。
时间: 2024-09-30 21:16:06