【问题标题】:std::ifstream doesn't open filestd::ifstream 不打开文件
【发布时间】:2021-06-03 15:47:00
【问题描述】:

我试图打开一个文件,就像其他人一样,但它不起作用。 我浪费了太多时间寻找解决方案和东西,但什么也没有! 在我的另一个项目中,它可以工作,但在这里不行。

我不知道这是否与任何事情有关,但我在打开 std::ifstream 时仍然打开了一个 std::ofstream(“流”变量)

顺便说一句。文件路径是: C:\Users\no\Desktop\GlassStudios\GlassEngine\Source\x64\Debug\Content\Asset.txt

将反斜杠更改为斜杠(“/”)也不起作用

这是我的代码:

for (size_t i = 0; i < tmpfl.size(); i++) // tmpfl is a std::list<std::string>
        {
            std::ifstream data(tmpfl.begin()->c_str(), std::ios::binary); // Stream is empty all the time
            tmpfl.pop_front();

            int start = stream.tellp(); // this is for an unrelated part

            while (!stream.eof()) // this is for an unrelated part
            {
                WriteEncrypted(key, (char)data.get(), &stream); // this is for an unrelated part
            }

            data.close(); // this is for an unrelated part

            int end = stream.tellp(); // this is for an unrelated part
        }

请帮忙

【问题讨论】:

    标签: c++ io fstream ifstream


    【解决方案1】:

    您是否在文件路径中使用“\\”而不是 \?

    (像这样)

    C:\\Users\\no\\Desktop\\GlassStudios\\GlassEngine\\Source\\x64\\Debug\\Content\\Asset.txt

    此外,有时防病毒软件会阻止您的程序打开其他位置的文件,您可能必须手动进入防病毒软件并允许您的程序访问计算机上的其他位置。

    【讨论】:

    • 不,\\ 被转义了,所以从技术上讲它只是 \ 并且禁用防病毒也不起作用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多