首页 > 解决方案 > ofStream 中的错误,Qt 5.14.2 无法将字符串写入文件

问题描述

我正在尝试从 VS (MVCS) 为 Qt(MinGb) 编写我的程序,我正在使用 ofstream 并具有以下代码:

#include <fstream>
#include <string>
#include <iostream>
#include <exception>
using namespace std;
void WriteToFile(ofstream* fileToWrite, std::string StringNeedsToWrite)
{
    if (fileToWrite)
    {
        if (IsStartOfNewString(StringNeedsToWrite))
        {
            *fileToWrite << '\n';
        }
        *fileToWrite << StringNeedsToWrite;     
    }
    else
    {
        throw exception();
    }
}

我想将字符串写入文件,并将 ofstream 设置到我的方法中。但我有一个奇怪的错误,不知道如何修复它(图片上)

图像错误

标签: c++stringqtmingwofstream

解决方案


它们的 make 文件和项目文件不同。一个常见的问题是,将项目从一个环境转移到另一个环境会导致重大错误。比如Linux下的MinGW没有标准流,但是有.windows.h

在开发程序架构和选择开发技术的阶段应该考虑和研究这些问题。

频繁的实践表明,Qt最适合与您的IDE一起使用,并且如果可能的话,使用它的类进行开发。


推荐阅读