Unicode File I/O problem
-
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 <
-
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 <
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 localelocale default_locale = wcout.getloc(); cout << default_locale.name();
which if nothing has been imbued is C for classic //create a new localelocale french_locale("french");
//reveal its namecout << 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 localelocale 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[^]