collection class using indexing

I need to write an entire class with a main method that       (using the 'next'  and  'hasNext'  functions)

 1 -  creates a collection of names called 'theNames'   (type string)

  2- prompts for and reads from the screen five values for 'theNames' and  adds  them into the collection without indexing.  It may require an appropriate value to teminate the data entry.

 3 - Prints the values back out without indexing
usumleAsked:
Who is Participating?
 
Jaime OlivaresSoftware ArchitectCommented:
you can use a list template:


using namespace std;
list<string> theNames;

to add values just use:
theNames.push_back(somestring);

to iterate:
list<string>::iterator i;
for (i=theNames.begin(); i!=theNames.end(); i++) {
     // some operation with (*i), by example:
     cout << (*i) << endl;
}
0
 
usumleAuthor Commented:
good  good,   it runs fine ,  thanks
0
 
Jaime OlivaresSoftware ArchitectCommented:
Appear to be that you forgot to Accept the answer...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.