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

  • Home
  • SEARCH
  • 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 7559383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:37:18+00:00 2026-05-30T12:37:18+00:00

Im having some trouble with an Array in C++. See I want to let

  • 0

Im having some trouble with an Array in C++.
See I want to let the user give the program an input in form of a String, and keep doing it until the user is satisfied. My input is working fine but when i want to store the strings in to an array im running in to some problems. I have to define a size for my array apparently? and is there a way to store the input in 2 or 3 different arrays (depending on the input, which i sort with some if-statements) of strings, and the print them out?
My code looks something like this now..

string firstarray[10];
string secarray[10];

//The cin stuff here and reading strings from user-input

    if(MyCondition1){ 
for(int x = 0; x<=9;x++){ 
firstarray[x] = name;  
}

  if(MyCondition2){ 
    for(int x = 0; x<=9;x++){ 
    secarray[x] = name;  
    }

Is there a way to skip the 10-limit of an array? could it be like string

firstarray[];

?

  • 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-05-30T12:37:19+00:00Added an answer on May 30, 2026 at 12:37 pm

    You’re looking for a std::list. Or better, a std::vector which lets you access elements by their position.

    Both of them can be expanded dynamically.

    using namespace std;
    
    // looks like this:
    vector<string> firstvector;
    
    firstvector.push_back(somestring); // appends somestring to the end of the vector
    
    cout << firstvector[someindex]; // gets the string at position someindex
    cout << firstvector.back(); // gets the last element
    

    About your second question:
    You can of course create several arrays / vectors to put your strings in. Maybe even use a std::map of type map<key, vector<string>> where key can be an enum for the category (or a string, but enum is better).

    You put a new value into one of the vectors:

    tCategoryEnum category = eCategoryNone;
    switch(condition)
    {
      case MyCondition1:
        category = eCategory1;
        break;
      case MyCondition2:
        category = eCategory2;
        break;
      // ...
    }
    // check if a category was found:
    if(category != eCategoryNone)
    {
        categoryMap[category].push_back(name);
    }
    

    Then to output this, you can simply loop over each category and vector element

    for(int i = 0; i < categoryMap.size(); i++)
      for(int j = 0; j < categoryMap[i].size(); j++)
        cout << categoryMap[i][j];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble with matching some form input to a value in an array.
I'm having some trouble importing and accessing a private key with the ASPNET user.
I am having some trouble inserting an array into the sql database. my error
I'm having trouble submitting some hidden form data via post from the following function:
I am having some trouble populating a large plist into an array. Here is
I am having some trouble marshaling a pointer to an array of strings. It
I'm having some trouble mapping a byte array to a MySQL database in Hibernate
I'm trying to create an associative array with dynamic data, and having some trouble.
I'm having some trouble adding a mutable string (that has been changed with replaceOccurrencesOfString)
I am dynamically trying to populate a multidimensional array and having some trouble. I

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.