Posted on 2005-05-07
Medium Priority
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
  • 2
LVL 55

Expert Comment

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

Author Comment

ID: 13950763
can you supply any code examples, please?
LVL 55

Accepted Solution

Jaime Olivares earned 2000 total points
ID: 13950795
#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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

862 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