Solved

Search through vector.  Help!

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

759 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