メモリを動的に割り当てる必要があります。この場合のスタックは、それほど多くのデータを保持するのに十分な大きさではありません。
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
}