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. C / C++ / MFC
  4. Search for a word in a file from code

Search for a word in a file from code

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 2 Posters 0 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
    bugDanny
    wrote on last edited by
    #1

    Is there a way to search for a particular word in a file, no matter where it may be placed. I don't think opening the file and just using getline will work. Maybe there is a tool out there I can make use of in my code? Danny

    D 1 Reply Last reply
    0
    • B bugDanny

      Is there a way to search for a particular word in a file, no matter where it may be placed. I don't think opening the file and just using getline will work. Maybe there is a tool out there I can make use of in my code? Danny

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      bugDanny wrote: Is there a way to search for a particular word in a file, no matter where it may be placed. Sure. Open the file. Read the contents into a buffer. Search that buffer. Are you using C++, MFC, or just the Windows SDK?


      "One must learn from the bite of the fire to leave it alone." - Native American Proverb

      B 1 Reply Last reply
      0
      • D David Crow

        bugDanny wrote: Is there a way to search for a particular word in a file, no matter where it may be placed. Sure. Open the file. Read the contents into a buffer. Search that buffer. Are you using C++, MFC, or just the Windows SDK?


        "One must learn from the bite of the fire to leave it alone." - Native American Proverb

        B Offline
        B Offline
        bugDanny
        wrote on last edited by
        #3

        I'm using C++, but I could use MFC if needed. I suppose I was thinking of using getline to read the contents of the file word by word. You mean that I should read the whole file into a buffer, not just word by word. That would make it a lot easier to go back and forth in my search. I suppose I just didn't think of it that way. Danny

        D 1 Reply Last reply
        0
        • B bugDanny

          I'm using C++, but I could use MFC if needed. I suppose I was thinking of using getline to read the contents of the file word by word. You mean that I should read the whole file into a buffer, not just word by word. That would make it a lot easier to go back and forth in my search. I suppose I just didn't think of it that way. Danny

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          bugDanny wrote: You mean that I should read the whole file into a buffer, not just word by word. Correct.


          "One must learn from the bite of the fire to leave it alone." - Native American Proverb

          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