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. Reading Unicode from a text file

Reading Unicode from a text file

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++
10 Posts 6 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.
  • L Offline
    L Offline
    LCI
    wrote on last edited by
    #1

    I am trying to read the Unicode output from an application. the application writes strings out to a .txt file using : L"Date, Time, 150" I am trying to read the value of the number, but since it is unicode, this is not a straight ReadFile operation. Is there any way in MFC to do this nice and clean. I know C# has some built in functionality to make a conversion to interpret the text. Thanks,

    C _ M S 4 Replies Last reply
    0
    • L LCI

      I am trying to read the Unicode output from an application. the application writes strings out to a .txt file using : L"Date, Time, 150" I am trying to read the value of the number, but since it is unicode, this is not a straight ReadFile operation. Is there any way in MFC to do this nice and clean. I know C# has some built in functionality to make a conversion to interpret the text. Thanks,

      C Offline
      C Offline
      Code o mat
      wrote on last edited by
      #2

      Every (or at least most) text-file read operations have their widechar (unicode) versions, like for fgets there is fgetws. Did you try using those?

      > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

      1 Reply Last reply
      0
      • L LCI

        I am trying to read the Unicode output from an application. the application writes strings out to a .txt file using : L"Date, Time, 150" I am trying to read the value of the number, but since it is unicode, this is not a straight ReadFile operation. Is there any way in MFC to do this nice and clean. I know C# has some built in functionality to make a conversion to interpret the text. Thanks,

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #3

        You just need to specify the number of bytes to read in the ReadFile API. Unicode and non-unicode is decided based upon how it is interpreted. So you're probably not giving the correct number of bytes to read. Try doubling it.

        «_Superman_» I love work. It gives me something to do between weekends.

        1 Reply Last reply
        0
        • L LCI

          I am trying to read the Unicode output from an application. the application writes strings out to a .txt file using : L"Date, Time, 150" I am trying to read the value of the number, but since it is unicode, this is not a straight ReadFile operation. Is there any way in MFC to do this nice and clean. I know C# has some built in functionality to make a conversion to interpret the text. Thanks,

          M Offline
          M Offline
          Michael Schubert
          wrote on last edited by
          #4

          You mentioned MFC so I suggest you use CStdioFile to read text files. You have to set the flag CFile::typeBinary in order to read Unicode strings and of course your app has to be Unicode enabled.

          L 1 Reply Last reply
          0
          • M Michael Schubert

            You mentioned MFC so I suggest you use CStdioFile to read text files. You have to set the flag CFile::typeBinary in order to read Unicode strings and of course your app has to be Unicode enabled.

            L Offline
            L Offline
            LCI
            wrote on last edited by
            #5

            When you say that the app has to be Unicode enabled, do you mean building it as Unicode as opposed to release?

            M C 2 Replies Last reply
            0
            • L LCI

              When you say that the app has to be Unicode enabled, do you mean building it as Unicode as opposed to release?

              M Offline
              M Offline
              Michael Schubert
              wrote on last edited by
              #6

              You have to define _UNICODE and UNICODE and you have to set the Entry-Point symbol in the Linker output options to wWinMainCRTStartup That's for both configurations, Release and Debug.

              L 1 Reply Last reply
              0
              • L LCI

                I am trying to read the Unicode output from an application. the application writes strings out to a .txt file using : L"Date, Time, 150" I am trying to read the value of the number, but since it is unicode, this is not a straight ReadFile operation. Is there any way in MFC to do this nice and clean. I know C# has some built in functionality to make a conversion to interpret the text. Thanks,

                S Offline
                S Offline
                Sarath C
                wrote on last edited by
                #7

                See this A UTF-16 Class for Reading and Writing Unicode Files[^]

                -Sarath. "Great hopes make everything great possible" - Benjamin Franklin

                My blog - Sharing My Thoughts

                1 Reply Last reply
                0
                • M Michael Schubert

                  You have to define _UNICODE and UNICODE and you have to set the Entry-Point symbol in the Linker output options to wWinMainCRTStartup That's for both configurations, Release and Debug.

                  L Offline
                  L Offline
                  LCI
                  wrote on last edited by
                  #8

                  Oh i see... So if i just do this: "You have to define _UNICODE and UNICODE and you have to set the Entry-Point symbol in the Linker output options to wWinMainCRTStartup" Is that equivalent to building as unicode or does that serve a totally different purpose relating to the output of the application?

                  M 1 Reply Last reply
                  0
                  • L LCI

                    When you say that the app has to be Unicode enabled, do you mean building it as Unicode as opposed to release?

                    C Offline
                    C Offline
                    Cedric Moonen
                    wrote on last edited by
                    #9

                    LCI wrote:

                    do you mean building it as Unicode as opposed to release?

                    Unicode is not 'opposed' to Release. You can build unicode enabled applications both in debug and release modes.

                    Cédric Moonen Software developer
                    Charting control [v1.5] OpenGL game tutorial in C++

                    1 Reply Last reply
                    0
                    • L LCI

                      Oh i see... So if i just do this: "You have to define _UNICODE and UNICODE and you have to set the Entry-Point symbol in the Linker output options to wWinMainCRTStartup" Is that equivalent to building as unicode or does that serve a totally different purpose relating to the output of the application?

                      M Offline
                      M Offline
                      Michael Schubert
                      wrote on last edited by
                      #10

                      LCI wrote:

                      Is that equivalent to building as unicode

                      Yes. The output of your app depends entirely on the functions/classes you use for writing to files.

                      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