Solved

Search through vector.  Help!

Posted on 2004-10-17
5
194 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now