您需要动态分配内存:您的情况下的堆栈不足以容纳那么多数据
const size_t len = 10;
string* str[len];
for(long i=0; i<len; ++i) {
str[i] = new string[100000];
}
注意:不要忘记在不再需要时删除分配的内存。
注意:为了让生活更轻松,请使用适当的容器(例如vector<>
)自动为您进行内存管理
更新:您的代码也有一些其他问题:
for(long i=0;i<=t;i++) // t could be lager than 9
{
getline(cin,str[i][100000]); // you are accessing a non-existent element
}
请尝试:
long t;
cin>>t;
vector<string> str; // declare an auto-resizing container of strings
for(long i=0; i<t; i++)
{
string tmp; // this string will be able to store a lot of characters by itself
getline(cin, tmp); // read in the next line
str.push_back(tmp); // add the line to our container
}
for(long i=0; i<t; i++)
{
// do something with str[i] // values str[0]..str[t-1] are guaranteed to be valid
}