?
Solved

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

Posted on 2003-03-09
3
Medium Priority
?
232 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

752 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