问题 文件结束符
//4-35.cpp#include<iostream>
#include <vector>
#include <string>
using namespace std;
int main (){
vector<string> svec;
string str;
cout<<"enter strings:ctrl+z to end"<<endl;
while (cin>>str)
svec.push_back(str);
char **parr=new char *[svec.size()];
size_t ix=0;
for (vector<string>::iterator iter=svec.begin();
iter!=svec.end();++iter,++ix){
char *p=new char [(*iter).size()+1];
strcpy(p,(*iter).c_str());
parr[ix]=p;
}
cout<<"vector:"<<endl;
for(vector<string>::iterator iter2=svec.begin();
iter2!=svec.end();++iter2)
cout<<*iter2<<endl;
cout<<"arrays"<<endl;
for(ix=0;ix!=svec.size();++ix)
cout<<parr[ix]<<endl;
for(ix=0;ix!=svec.size();++ix)
delete[] parr[ix];
delete[] parr;
return 0;
}
这是c++primer上的,我在vs2010运行了一下,即使是回车再ctrl z都没反应。只出现^z.。。。。。。。