c++ - std::ofstream 不接受 << 运算符的 const char *

标签 c++ visual-studio-2015 ofstream

我已将我的 C++ 项目从 VS 2010 升级到 2015,但在编译时遇到了一些问题。方法头如下所示:

void CCodeGenerator::GenerateCode(const MachineExArray & AMachineExArray,
    const MachineArrays & AMachineArrays,
    std::ofstream & HeaderFile,
    std::ofstream & SourceFile)

有一行:

std::string HeaderDefine = path(OutputFilename).filename().generic_string();

for (std::string::iterator Iter = HeaderDefine.begin(); Iter != HeaderDefine.end(); Iter++)
    *Iter = toupper((unsigned char)*Iter);

HeaderDefine = "__" + HeaderDefine + "_H__";

HeaderFile << "#ifndef " << HeaderDefine << "\n"; // <-- This one

编译器在这里停止并说:

No operator "<<" matches these operands. Operand types are: std::ofstream << const char[9]

我很久以前用 C++ 编写过,但据我所知,std::ofstream 非常自由,应该接受大多数简单类型作为输入。问题出在哪里?


当我开始写 HeaderFile. 时,它立即被标记为错误(红色下划线)并且注释说“不允许不完整的类型”。

最佳答案

观察

"Incomplete types are not allowed"

.错误。

#include <ostream>

int main()
{
    std::ofstream HeaderFile;
}

也给出了这个错误,而这个

#include <fstream>

int main()
{
    std::ofstream HeaderFile;
}

在 VS2015 中编译。

关于c++ - std::ofstream 不接受 << 运算符的 const char *,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41300922/

相关文章:

oracle - Visual Studio 2015 Oracle 连接问题中的 SSDT

C++ 不正确的循环算法(或文件处理问题)

c++ - 如何使用 << 添加一个空格来填充带有 ofstream 的减号?

c++ - 是否有(更)合理的方法来确定 ostream 所针对的终端的宽度?

c++ - 如果 compile-time-constant 参数错误,则生成编译时错误

C++模板特化方法定义

c# - 让 VS2015 验证 C# 早期语法以保持与 VS2013 兼容的方法

c++ - 如何在 C++ 中创建代码发射器

c++ - 如何在不更改 C++ 中的原始链表的情况下反转链表

visual-studio - 停止 Typescript 发出 @class 注释