![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Problem about the return value type of generic algorithm find().Hi,
I know the return value of generic search algorithm "find()" is of iterator type. Now how can I output the return value as numeric type? For example: CPP / C++ / C Code:
|
|||
|
#2
|
|||
|
|||
Re: Problem about the return value type of generic algorithm find().Are you looking to get the index at which the element was found? Or are you looking to get the value of an iterator? I'll assume the former since by virtue of having the iterator and search term you already have all the ingredients for the latter.
I dont know that there is a direct way to do that with the iterator without keeping an index and comparing each element in the vector. If that is the case, you may be better off just iterating over the vector by hand anyway. __________________
My personal site: Utilities for text processing, debugging, testing and plotting |
|
#3
|
||||
|
||||
Re: Problem about the return value type of generic algorithm find().You can dereference the returned iterator:
CPP / C++ / C Code:
Best regards, Lucian __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#4
|
||||
|
||||
Re: Problem about the return value type of generic algorithm find().Quote:
After reading your post I realize the OP was probably asking about the numeric index. You can subtract iterators in a vector: CPP / C++ / C Code:
Of course, the proper checks should be made (std::find will return end if it can't find the item). Best regards, Lucian __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
Recent GIDBlog
Install Adobe Flash - Without Administrator Rights by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| "Linker Error" problem with C++ | The Great Dane | C++ Forum | 3 | 29-Jan-2010 04:29 |
| Airport Log program using 3D linked List : problem reading from file | batrsau | C Programming Language | 11 | 29-Feb-2008 07:44 |
| yet another linked list program | aijazbaig1 | C Programming Language | 15 | 11-Sep-2007 13:18 |
| Re: Things to Avoid in C/C++ -- gets() , Part 1 | WaltP | C Programming Language | 5 | 21-Jun-2007 12:13 |
| [Include] Doubly-linked List | dsmith | C Programming Language | 6 | 14-Apr-2006 13:12 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The