Possible Duplicate:
Very large array on the heap (Visual C++)
i need to declare 10 strings each of length 100000 characters long.
int main(void)
{
long t;
cin>>t;
string str[10][100000];
for(long i=0;i<=t;i++)
{
getline(cin,str[i][100000]);
}
for(long i=1;i<=t;i++)
{
getStringSize(str[i][100000]);
}
system("PAUSE");
}
i wrote the code in VC++ but as soon as i compile the code i have a stack overflow.
if i keep the size of the string to str[10][10000] then the code works great. what do i need to make to code work?
You need to allocate the memory dynamically: the stack in your case is not big enough to hold that much data
Note: Don’t forget to delete the allocated memory when you no longer need it.
Note: To make life easier, use an appropriate container (e.g.
vector<>) that does the memory management for you automaticallyUpdate: your code has some other problems too:
Try instead: