#include
#include
#include
using namespace std;
int main(){
vector strvec;
string str;
cout << "please enter some string,Ctrl+Z to end:" << endl;
while (cin >> str)
strvec.push_back(str);
for (vector::iterator it = strvec.begin(); it != strvec.end(); it++)
cout << *it << endl;
//创建字符指针数组
char **strpoi = new char*[strvec.size()];
//处理指针数组
size_t ix = 0;
for (vector<string>::iterator iter = strvec.begin(); iter != strvec.end(); ++iter, ++ix)
{
char *p = new char[(*iter).size()+1];
strcpy_s(p,(*iter).c_str());
strpoi[ix] = p;
cout << *p << endl;
cout << strpoi[ix] << endl;
}
for (size_t j = 0; j < strvec.size(); j++)
delete[] strpoi[j];
delete[]strpoi;
system("pause");
return 0;
}
为什么这段代码出现错误。
strcpy_s(p,(*iter).c_str());
strpoi[ix] = p;
这句里出错了