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 6723105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:31:43+00:00 2026-05-26T09:31:43+00:00

I am using a vector of strings in order to store some data in

  • 0

I am using a vector of strings in order to store some data in memory. Database is not an option. More precisely an array of vector of strings. A simple scenario: I need to store the names of people living in 256 cities.

Example

NewYork: John, Bod, ...
London: Jim, Bill...

for this requirement I used

vector<std::string> city[256];

A new requirement came to create a new “class Person” that will hold more data per item

class person {
 string name;
 string surname;
 string email;
 int age;
};

I am addressing this issue in order to find the optimal way to store and shared those data.

vector<class person> city[256];

Obviously is better to use a pointer to objects. does shared_ptr applies here? We have TR1
installed in the system but we cannot use boost libs.

  • 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-26T09:31:44+00:00Added an answer on May 26, 2026 at 9:31 am

    If you have C++11 and only need a single, global version of this data, you could use a data structure like this:

    #include <unordered_map>
    #include <unordered_set>
    #include <string>
    
    typedef std::unordered_multiset<std::string> name_set;
    typedef std::unordered_map<std::string, name_set> city_map;
    
    city_map city_db {
      { "Moscow", { "Ivan", "Igor", "Vladimir" } },
      { "Madrid", { "Julio", "Pedro", "Sanchez" } },
      { "Munich", { "Sepp", "Huber", "Maier" } }
    };
    
    int main()
    {
      return city_db["Munich"].size(); // just as an example
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using http://www.phpaes.com/ to encrypt some values and store them in a MySQL database.
I save some values from database using this function (i've been replaced Vector, because
In c++, is using a vector of objects a good idea? If not, what's
I'm using the support vector machine from the e1071 package to classify my data
Many data mining algorithms/strategies use vector representation of data records in order to simulate
I've created a 2d array of c-strings using : char ** my_array = new
I have an std::vector of std::strings containing data similar to this: [0] = ""
I'm trying to test a simple SQLite database using Robolectric in my Android application.
I'm using the 'using' declaration in C++ to add std::string and std::vector to the
Please take a look at this example: #include <iostream> #include <vector> #include <string> using

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.