我无法使用calloc创建字符串数组。我不确定数组是否未被创建。程序崩溃时,我尝试设置字符串值:C++ calloc字符串数组
using namespace std;
int main(void){
int counts;
string* strs;
cout<<"Enter a number: ";
cin>>counts;
cout<<endl;
strs=(string*)calloc(counts,sizeof(string));
for(int i=0;i<counts;i++){
strs[i] = "Hello World!";
cout<<i<<") "<<strs[i]<<endl;
}
return 0;
}
我使用也尝试:
strs[i].asign("Hello World");
,但我仍然得到一个Windows错误“的错误导致程序停止正常工作“
任何帮助将是伟大的!