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. Desperately need your help. A weird problem about CString

Desperately need your help. A weird problem about CString

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++debuggingquestionlearning
3 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.
  • E Offline
    E Offline
    ewighell
    wrote on last edited by
    #1

    First, UNICODE has been defined in my program. Second, my CString involves Chinese characters as well as English letters. the following piece of code runs correctly and the format of the resulted file "myTxt.txt" is Unicode

    CFile file(_T("myTxt.txt"), CFile::modeCreate|CFile::modeWrite);
    CArchive ar(&file, CArchive::store, 512);
    CString str;
    str = _T("Welcome 张三");
    TRACE(str); //no error
    ar.WriteString(str);

    however, the following piece of code dose not run correctly and the format of the resulted file "myTxt.txt" is ANSI

    CFile file(_T("myTxt.txt"), CFile::modeCreate|CFile::modeWrite);
    CArchive ar(&file, CArchive::store, 512);
    CString str;
    str = m_ListCtrl.getItemText(0,0);
    TRACE(str); //no error
    ar.WriteString(str);

    isn't it weird? anybody has any idea?

    Thank you very much!!! ------------------- I am learning C++ and English

    H 1 Reply Last reply
    0
    • E ewighell

      First, UNICODE has been defined in my program. Second, my CString involves Chinese characters as well as English letters. the following piece of code runs correctly and the format of the resulted file "myTxt.txt" is Unicode

      CFile file(_T("myTxt.txt"), CFile::modeCreate|CFile::modeWrite);
      CArchive ar(&file, CArchive::store, 512);
      CString str;
      str = _T("Welcome 张三");
      TRACE(str); //no error
      ar.WriteString(str);

      however, the following piece of code dose not run correctly and the format of the resulted file "myTxt.txt" is ANSI

      CFile file(_T("myTxt.txt"), CFile::modeCreate|CFile::modeWrite);
      CArchive ar(&file, CArchive::store, 512);
      CString str;
      str = m_ListCtrl.getItemText(0,0);
      TRACE(str); //no error
      ar.WriteString(str);

      isn't it weird? anybody has any idea?

      Thank you very much!!! ------------------- I am learning C++ and English

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      You dont need to delete your message you can modify your message. See Easy text document conversion - ANSI/Unicode and Unicode/ANSI[^]

      _**


      **_

      WhiteSky


      E 1 Reply Last reply
      0
      • H Hamid Taebi

        You dont need to delete your message you can modify your message. See Easy text document conversion - ANSI/Unicode and Unicode/ANSI[^]

        _**


        **_

        WhiteSky


        E Offline
        E Offline
        ewighell
        wrote on last edited by
        #3

        thank you ------------------- I am learning C++ and English

        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