c++ - 无法在 C++ 中读取带有西里尔路径的文件

标签 c++ windows io fstream ifstream

我正在尝试读取路径中包含西里尔字符的文件,并得到 ifstream.is_open() == false 这是我的代码:

std::string ReadFile(const std::string &path) {
    std::string newLine, fileContent;
    std::ifstream in(path.c_str(), std::ios::in);

    if (!in.is_open()) {
        return std::string("isn't opened");
    }

    while (in.good()) {
        getline(in, newLine);
        fileContent += newLine;
    }

    in.close();

    return fileContent;
}

int main() {
    std::string path = "C:\\test\\документ.txt";
    std::string content = ReadFile(path);
    std::cout << content << std::endl;
    return 0;
}

指定文件存在

我试图在谷歌中找到解决方案,但我一无所获

这是我看到的链接:

I don't need wstring

The same as previous

no answer here

is not about C++

has no answer too

附言我需要在字符串中获取文件的内容,而不是在 wstring 中

这是我的 IDE (CLION 2017.1) 的编码设置

My encoding

最佳答案

您需要一个最新的编译器或 Boost。 std::filesystem::path 可以处理这些名称,但它是 C++17 标准中的新内容。您的编译器可能仍将其作为 std::experimental::filesystem::path,否则您将使用第三方 boost::filesystem::path。这些界面非常相似,因为 Boost 版本是灵感来源。

关于c++ - 无法在 C++ 中读取带有西里尔路径的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43405956/

相关文章:

c++ - 如何为 multimap 的插入和删除功能编写 API?

c++通过csv文件和最后一列进行解析

windows - 无法在 Windows 7 上启动 glassfish v3

windows - 避免从锁定构建目录的东西中彻底失败(并因此构建)

c++ - OpenGL 获取设备上下文

windows - C++使用SSL保证Windows上Winsock TCP数据安全

hadoop - Hadoop YARN:如何管理I/O

java - 我想使用 Java 在文件的最后一行添加一些字符串,但我遇到了困难,需要帮助 :)

c++ - 流对象表示文件输入然后是标准输入?

c++ - OpenGL - gluOrtho2d 和 glLoadIdentity?