to use boost::filesystem with UTF-8 path?
This piece of code show an example to convert a string from latin1 charset to UTF-8 without changing the system locale.
#include <iostream>
#include <fstream>
#include <vector>
{
if (fooCfgPath == "")
{
std::cerr << "Could not find foo.cfg" << std::endl;
std::cerr << "Looked in: " << std::endl;
std::vector<std::string>::const_iterator it;
for (it = configPaths.begin(); it != configPaths.end(); ++it)
{
std::cerr << "\t" << *it << std::endl;
}
}
else
{
std::cout << "Found foo.cfg: " << fooCfgPath << std::endl;
std::cout << "Contents: " << std::endl;
char buf[250];
std::ifstream ifs;
ifs.open(fooCfgPath.c_str(), std::fstream::in);
while (! ifs.eof())
{
ifs.getline(buf, 250);
std::cout << buf << std::endl;
}
ifs.close();
}
std::cout << "Writing config file to: " << userCfgPath << std::endl;
std::ofstream ofs(userCfgPath.c_str(), std::fstream::out | std::fstream::trunc);
ofs << "Hi, this is foo.cfg" << std::endl;
ofs.close();
return 0;
}