Posted on 2005-05-07
Last Modified: 2013-12-14
I need to store a list of strings and to be able to access n-th element of this list. In which convenient way would you suggest to implement it (what data type and example how to get n-th element)
Question by:Buffon
    LVL 55

    Expert Comment

    by:Jaime Olivares
    definitively a vector<>, since list<> is not efficient for this task
    LVL 11

    Author Comment

    can you supply any code examples, please?
    LVL 55

    Accepted Solution

    #include <iostream>
    #include <string>
    #include <vector>
    using namespace std;


    vector<string> myStrings;

    string a = "some string";
    string b = "another string";
    string c = "last string";


    cout << "String 1: " << myStrings[0] << endl;   // Notice zero-based array index
    cout << "String 2: " << myStrings[1] << endl;
    cout << "String 3: " << myStrings[2] << endl;

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
    THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now