int trim(string &s)
{
if (s.empty())
{
return 0;
}
s.erase(0,s.find_first_not_of(" "));
s.erase(s.find_last_not_of(" ") + 1);
return 0;
}
int main(){
/*char c;
showMenu();
c=getchar();
//我认为应该是不断操作文件吧,而不是说取出来放到内存里
//还是放到内存吧,用结构体
while(c!='Q'){
if(c=='P'){//直接读取默认位置的文件
}
else if(c=='A'){
}
}*/
fstream fs("databaseShop.txt",ios::in|ios::out|ios::app);
if(!fs){
printf("open file wrongly!\n");
return 1;
}
//getline必须只能用string,而不能用char。
string sentence=" this is the 2142whole ";
trim(sentence);// 是string&
cout<<sentence<<endl;
while(!sentence.empty()&&sentence.size()>0){
int pos=sentence.find(' ');
string sub=sentence.substr(0,pos);
sentence=sentence.erase(0,pos);
trim(sentence);
cout<<"First sub:"<<sub<<endl;
cout<<"Left sentence:"<<sentence<<endl;
}
getchar();
getchar();
return 0;
}