Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7991521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:18:51+00:00 2026-06-04T13:18:51+00:00

Possible Duplicate: Very large array on the heap (Visual C++) i need to declare

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:18:53+00:00Added an answer on June 4, 2026 at 1:18 pm

    You need to allocate the memory dynamically: the stack in your case is not big enough to hold that much data

    const size_t len = 10;
    string* str[len]; 
    for(long i=0; i<len; ++i) {
      str[i] = new string[100000];
    } 
    

    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 automatically

    Update: your code has some other problems too:

    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
    } 
    

    Try instead:

    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
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Very large HTTP request vs many small requests I need a 2D
Possible Duplicate: C dynamically growing array I have a program and I need to
Possible Duplicate: Console.Readline() max length? In my attempt to find a very simple text
Possible Duplicate: Quickly reading very large tables as dataframes in R Hi, trying to
Possible Duplicate: What are the performance characteristics of sqlite with very large database files?
Possible Duplicate: wordwrap a very long string My code <div style=width:40px;>adfdddddddddddddddddddd</div> This code should
Possible Duplicate: String comparison in Objective-C I realize that the question is not very
Possible Duplicate: Objective-C style formatter I'm very picky about the formatting of my Objective
Possible Duplicate: Rails primary key and object id Very quick question. My server is
Possible Duplicate: Can you do Desktop Development using JavaScript? I am very familiar with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.