这是什么情况
就是一个cin的问题,为什么看上去cin>>filename 这句像是把空字符传给了filename或者像是
根本没有被执行啊,求教。。
#include<iostream>#include<fstream>#include<string>#include<vector>using namespace std;int main(){ void save(string ,vector<string>); void output(vector<string>); vector<string> svec; string word; string filename; cout<<"initial file name:"<<" "<<filename<<endl; cout<<"Please input the wordlists"<<endl; while(cin>>word) svec.push_back(word); output(svec); cout<<"wordlist saved to:"<<endl; [b] cin>>filename;[/b] cout<<"The filename is "<<filename<<endl; save(filename,svec); return 0;}void save(string name,vector<string> svec){ ofstream save(name,ios::out); for(vector<string>::size_type i =0;i!=svec.size();i++) { if(i%5==0&&i>4) save<<"\n"<<svec[i]<<" "; else save<<svec[i]<<" "; } cout<<"wordlist saved to "<<name<<endl; } void output(vector<string> svec) { cout<<"The word list:"<<endl; for(vector<string>::size_type i=0;i!=svec.size();i++) { if(i%2==1) cout<<svec[i]<<endl; else cout<<svec[i]<<" "; } } int main(){ void save(string ,vector<string>); void output(vector<string>); vector<string> svec; string word; string filename; cout<<"initial file name:"<<" "<<filename<<endl; cout<<"Please input the wordlists"<<endl; while(cin>>word) svec.push_back(word); output(svec); cout<<"wordlist saved to:"<<endl; cin.clear(); cin.sync(); cin>>filename; cout<<"The filename is "<<filename<<endl; save(filename,svec); return 0;}void save(string name,vector<string> svec){ ofstream save(name.c_str(),ios::out); for(vector<string>::size_type i =0;i!=svec.size();i++) { if(i%5==0&&i>4) save<<"\n"<<svec[i]<<" "; else save<<svec[i]<<" "; } cout<<"wordlist saved to "<<name<<endl;}void output(vector<string> svec){ cout<<"The word list:"<<endl; for(vector<string>::size_type i=0;i!=svec.size();i++) { if(i%2==1) cout<<svec[i]<<endl; else cout<<svec[i]<<" "; }}