Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Search through vector.  Help!

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 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.

610 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