Teen Programmers Unite  
 

 

Return to forum top

another c++ question

Posted by sinple [send private reply] at January 13, 2003, 09:34:51 AM

hi

i posted similar to this before:

i have a vector in my project(i needed a vb collection equivilant type thing) and i t holds an 'array' of strings, i need to loop through each 'member' of hte vector and see if a very specific string exist within the string, if it does blah blah etc.

does anyone have a function, with an example\demo how to use it, that would be useful here. needs to be able to accept [(];" sort of characters

thx heaps

Posted by taubz [send private reply] at January 13, 2003, 10:13:28 AM

sinple, you need to ask a specific question. What part of the program do you need help with? Looping through the vector? Accessing the array of string? Checking if a string exists within another string? (For that someone already suggested the strstr function.)

I'm not being pedantic. Asking good questions is a necessary skill for programming.

- taubz

Posted by CViper [send private reply] at January 13, 2003, 11:52:16 AM

typedef std::vector<std::string> StrVec;

StrVec v;
v.push_back( "bleh" );    // add something
...

for( StrVec::iterator i = v.begin(); i != v.end(); ++i )
{
    if( strstr( (*i), "substr" ) )
        // found
}
Posted by taubz [send private reply] at January 13, 2003, 12:28:35 PM

Or we can just provide the entire program for you.

Posted by CViper [send private reply] at January 13, 2003, 03:52:52 PM

it wasn't *that* bad :/

Posted by sinple [send private reply] at January 14, 2003, 08:29:49 PM

k
i didn't understand the usage of the strstr and whether it was possible to use it in the vec loop.
sorry for the unspecific Q, but thanks for you help.

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.