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. Managed C++/CLI
  4. Unicode File I/O problem

Unicode File I/O problem

Scheduled Pinned Locked Moved Managed C++/CLI
help
2 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.
  • S Offline
    S Offline
    scottwalk
    wrote on last edited by
    #1

    I could use some help with a file i/o issue. I'm using simple fstream objects to read in a Unicode file, search it for a particular string, and print the line if it contains that string. Here's a snippet of my function: getline(traceFile, buffer); //pass getline the file stream object and string buffer pos = buffer.find(hr, 0); //set the position of string hr if found if (pos != string::npos) outFile << "Line Number " << count <<":"<< buffer <

    J 1 Reply Last reply
    0
    • S scottwalk

      I could use some help with a file i/o issue. I'm using simple fstream objects to read in a Unicode file, search it for a particular string, and print the line if it contains that string. Here's a snippet of my function: getline(traceFile, buffer); //pass getline the file stream object and string buffer pos = buffer.find(hr, 0); //set the position of string hr if found if (pos != string::npos) outFile << "Line Number " << count <<":"<< buffer <

      J Offline
      J Offline
      Jeremy Thornton
      wrote on last edited by
      #2

      firstly a good unicode editor helps: http://www.unipad.org/main/[^] secondly the STL way is to convert to wide strings and streams and (essential) use locales to 'imbue' them with the ability to handle the unicode conversion that you desire //include all the culture specific information you need #include <locale> //reveal the current locale locale default_locale = wcout.getloc(); cout << default_locale.name(); which if nothing has been imbued is C for classic //create a new locale locale french_locale("french"); //reveal its name cout << french_locale.name(); //French_France.1253 in windows //the names are non standard //but the locales construct happily with intuitive language name or abbreviation //see: http://www.microsoft.com/globaldev/nlsweb/default.asp[^] //set a new locale locale old_locale = wcout.imbue(french_locale); use the widen and narrow methods to convert and you should be away:-D a good code project article is here... http://www.codeproject.com/vcpp/stl/upgradingstlappstounicode.asp?df=100&forumid=16224&exp=0&select=557556[^]

      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