以下解決方法轉自百度知道:http://zhidao.baidu.com/question/335129108.html
boost庫中讀取xml的函數 read_xml的第一個參數不支持中文路徑?
using boost::property_tree::ptree; ptree pt; boost::array<string,400> tmpList; read_xml(“E:\新建文件夾\test.xml”, pt); 會拋異常 can not open 如何才能讓它支持中文路徑
boost內部實際上用的是STL的串流 有時候用ifstream或ofstream打開帶有中文路徑的文件會失敗。 解決辦法: 1、使用C語言的函數設置爲中文運行環境 setlocale(LC_ALL,"Chinese-simplified"); 2、使用STL函數設置爲系統語言環境 std::locale::global(std::locale("")); 當然選2啦!
boost::property_tree::wptree wpt;
std::locale::global(std::locale(""));
boost::property_tree::xml_parser::read_xml("E:\\新建文件夾\\test.xml",wpt);
經試用,方法是成功的。