Solved

Search through vector.  Help!

Posted on 2004-10-17
5
219 Views
Last Modified: 2010-04-01
I am trying to search through a vector of strings.  If the string is found, then I store it into a pointer array.  THere can be up to 4 elements in this pointer array.  Could someone provide me with sample code for this?

0
Comment
Question by:jewee
[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
  • 2
5 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 12335691
I think you need something like this:

string *strPtrArray[4];
int index=0;

vector<string> theStrings;
vector<string>::iterator i;

// Somewhere theStrings is filled

for(i = theStrings.begin(); i !=theStrings.end(); i++ )
{
    if (*i=="Some string") {
        strPtrArray[index++] = &(*i);
    }    
}
0
 
LVL 9

Expert Comment

by:tinchos
ID: 12335722
Experts

This is a duplicate question.
Please do not post here, post in the original one.

http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_21171921.html

Thanks in advance

Tincho
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12335777
I think is not exactly the same, although both can be combined.
0
 
LVL 9

Expert Comment

by:tinchos
ID: 12335795
Hi Jaime

I just thought that the 2 questions refer to the same problem, although written differently.

Tincho
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12335830
I have understood this:

This question is related to search a string into a vector of strings.
Refered question is related to mantain a collection of vector of strings to search in.
There is a third question right now: How to pass a null argument to the same function.
0

Featured Post

Independent Software Vendors: 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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

717 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