【问题标题】:Error in ofStream, Qt 5.14.2 can 't write string into fileofStream 中的错误,Qt 5.14.2 无法将字符串写入文件
【发布时间】:2020-10-28 11:56:03
【问题描述】:

我正在尝试从 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 设置到我的方法中。 但我有一个奇怪的错误,不知道如何修复它(在图片上)

【问题讨论】:

  • 您是否尝试将文件的方法指针传递给您的方法并在您的方法中创建流?
  • @bogdyname 请使用 SO 的官方语言英语。
  • @AndrewPilikin 请使用 SO 的官方语言英语。

标签: c++ string qt mingw ofstream


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2011-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-29
    • 2014-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多