?
Solved

Search through vector.  Help!

Posted on 2004-10-17
5
Medium Priority
?
224 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 2000 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

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

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…
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 …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.
Suggested Courses

770 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