c++ - 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 设置到我的方法中。但我有一个奇怪的错误,不知道如何修复它(图片上)
解决方案
它们的 make 文件和项目文件不同。一个常见的问题是,将项目从一个环境转移到另一个环境会导致重大错误。比如Linux下的MinGW没有标准流,但是有.windows.h
在开发程序架构和选择开发技术的阶段应该考虑和研究这些问题。
频繁的实践表明,Qt最适合与您的IDE一起使用,并且如果可能的话,使用它的类进行开发。
推荐阅读
- tensorflow - 有时我看到 Tensorflow session.run 只获取优化器,有时它同时获取优化器和成本。有什么不同?
- java - Java 8 流 | 文本文件中行的平均字数
- android - TimerTask 在服务中停止触发
- python - 将列表与数据框列进行比较并使用数字创建新列
- android - 操作栏中的 ImageView
- excel - SaveasCopy 代码 - 来自某些单元格的名称
- java - How to check that the entered input is an integer or not in java?
- python - 如何在电影评分推荐系统中为我的模型准确性应用归一化平均绝对值::
- angular - Why is the format 'HH:mm' not working in this DatePipe?
- c++ - 函数结束后指针会死吗?