std::ifstream open中文路径乱码

int _tmain(int argc, _TCHAR* argv[])
{
    //中文路径乱码 解决方案
    std::string strPackCfg = "D:\\中文路径测试\\test.dat";
    setlocale(LC_ALL,"Chinese-simplified");
    std::ifstream infile;
    infile.open(strPackCfg.c_str());
    cout<<"测试_1\n";
    if (!infile)
    {
        return 0;
    }
    setlocale(LC_ALL,"C");//还原
    cout<<"测试_2\n";
    if (!infile.is_open())
    {
        return 0;
    }
    std::string line;
    while (std::getline(infile, line))
    {
        if (line.empty())
            continue;
    }
    
    infile.close();
    return 0;
}

你可能感兴趣的:(C++学习笔记,setlocale,ifstream)