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. text file as custom resource

text file as custom resource

Scheduled Pinned Locked Moved C / C++ / MFC
questionlearning
4 Posts 4 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.
  • D Offline
    D Offline
    dene99970
    wrote on last edited by
    #1

    Lets say I have a text file named text1.txt, with a few lines of text. I want to include the file as resource in the .exe, so that no one can read the file. Then I want to be able to use it just as if it was an external file, such as std::ifstream fin('text1.txt'). What steps need to be taken so that that line of code std::ifstream fin('text1,txt'), will work for an internal resource?

    S S C 3 Replies Last reply
    0
    • D dene99970

      Lets say I have a text file named text1.txt, with a few lines of text. I want to include the file as resource in the .exe, so that no one can read the file. Then I want to be able to use it just as if it was an external file, such as std::ifstream fin('text1.txt'). What steps need to be taken so that that line of code std::ifstream fin('text1,txt'), will work for an internal resource?

      S Offline
      S Offline
      Stephen Hewitt
      wrote on last edited by
      #2

      It depends on which path you choose. If you want to be able to use it exactly as a file (i.e. open with CreateFile or std::ifstream) it would be a lot of work; don't even go down that road. The easiest way would be to write your own stream class that reads from resources; for this task I'd use the Boost.Iostreams[^] library.

      Steve

      1 Reply Last reply
      0
      • D dene99970

        Lets say I have a text file named text1.txt, with a few lines of text. I want to include the file as resource in the .exe, so that no one can read the file. Then I want to be able to use it just as if it was an external file, such as std::ifstream fin('text1.txt'). What steps need to be taken so that that line of code std::ifstream fin('text1,txt'), will work for an internal resource?

        S Offline
        S Offline
        S Douglas
        wrote on last edited by
        #3

        whenwood wrote:

        I want to include the file as resource in the .exe, so that no one can read the file.

        I believe much like dialogs, menus, toolbars and string resources file resources could easily be read using Visual Studio. Just open the binary with Visual Studio as a resource. If your intent is to ultimately store this information privately then encrypt it in a file. Trying to write info back to a file within the binary is error prone.


        I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:

        1 Reply Last reply
        0
        • D dene99970

          Lets say I have a text file named text1.txt, with a few lines of text. I want to include the file as resource in the .exe, so that no one can read the file. Then I want to be able to use it just as if it was an external file, such as std::ifstream fin('text1.txt'). What steps need to be taken so that that line of code std::ifstream fin('text1,txt'), will work for an internal resource?

          C Offline
          C Offline
          Cristian Amarie
          wrote on last edited by
          #4

          You can use, sure, import resource command in resource editor and choose the file as external file; the resulting binary will now contain a resource that can be accessed using FindResource, LoadResource, LockResource etc. (Perhaps is even better to use a separate dll only for this purpose). On the other hand, ifstream (basic_ifstream) have contructor only with a filename. Maybe basic_istream will do it, passing in constructor a basic_streambuf for resource and probably false for 2nd argument, _Isstd. I think implementing a derived class from basic_streambuf to use with the text resource file can do it.

          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