Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. Fast search of a vector of strings

Fast search of a vector of strings

Scheduled Pinned Locked Moved ATL / WTL / STL
graphicsalgorithmsquestion
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bruccutler
    wrote on last edited by
    #1

    Hello, I have the following code that searches a list of wchar_t * strings. What I want is a function like this: vector paths; find (paths.begin(), paths.end(), L"some string"); What do I need to do to get this to return the string I'm searching for? - BRC

    A 1 Reply Last reply
    0
    • B bruccutler

      Hello, I have the following code that searches a list of wchar_t * strings. What I want is a function like this: vector paths; find (paths.begin(), paths.end(), L"some string"); What do I need to do to get this to return the string I'm searching for? - BRC

      A Offline
      A Offline
      Andy Moore
      wrote on last edited by
      #2

      This will not return a string but an iterator to the matching string. Your code would look something like this.

      bool Comparer : public std::binary_function<wchar_t*, wchar_t*,bool>
      {
      public:
      bool operator()(const wchar_t* s1, const wchar_t* s2) const
      {
      return (wcscmp(s1, s2) == 0);
      }
      };

      std::vector<wchar_t*> paths;
      std::vector<wchar_t*>::const_iterator it;

      it = std::find_if(paths.begin(), paths.end(), std::bind2nd(Comparer(), L"some string"));

      if (it != paths.end())
      {
      /*Found it*
      const wchar_t* sz = *it;
      }

      ...

      Pax Domini sit semper vobiscum

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups