jkkkkkkksd 于 2015.06.20 21:06 提问

c++课设 车辆管理系统出错，求高人指教

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].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

1个回答

devmiao      2015.06.20 21:11