我已将我的 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/