?
Solved

Searching for a string in a number of files in a list

Posted on 2003-03-09
3
Medium Priority
?
238 Views
Last Modified: 2010-04-01
A list is compiled of a number of filenames, and these filenames need to be read from the list, in order, so that a string (specified by the user) can be found within one or many of the files represented by the filenames on the list.  How is such a list<string> traversed?  Must iterators be used? If so, how?
0
Comment
Question by:luciwe
2 Comments
 
LVL 2

Accepted Solution

by:
bkrahmer earned 240 total points
ID: 8098164
An iterator is probably the best method for traversing a list.  

using namespace std;
typedef list<string> StringList;
typedef StringList::iterator StringListIter;
...
StringList mylist;
mylist.push_back("a");
mylist.push_back("b");
...
StringListIter iter;
for (iter=mylist.begin(); iter!=mylist.end(); iter++)
{
  cout << (*iter).c_str() << endl;
}

cheers,
brian
0
 
LVL 11

Expert Comment

by:bcladd
ID: 9978784
No comment has been added lately, so it's time to clean up this TA. I will
leave a recommendation in the Cleanup topic area that this question is:

Answered: Points to bkrahmer: Grade A

Please leave any comments here within the next seven days.

Experts: Silence means you don't care. Grading recommendations are made in light
of the posted grading guidlines (http://www.experts-exchange.com/help.jsp#hi73).

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

-bcl (bcladd)
EE Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

616 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