[英]std::ofstream does not accept const char * for << operator
I've upgraded my C++ project from VS 2010 to 2015 and have some problems compiling it. 我已经将我的C ++项目从VS 2010升级到了2015,并且在编译时遇到了一些问题。 Method header looks like following:
方法标题如下:
void CCodeGenerator::GenerateCode(const MachineExArray & AMachineExArray,
const MachineArrays & AMachineArrays,
std::ofstream & HeaderFile,
std::ofstream & SourceFile)
There's a line: 有一行:
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
Compiler stops here and says: 编译器在这里停止并说:
No operator "<<" matches these operands.
没有运算符“ <<”与这些操作数匹配。 Operand types are: std::ofstream << const char[9]
操作数类型为:std :: ofstream << const char [9]
I wrote in C++ long ago, but from what I remember, std::ofstream
is quite liberal and should accept most of simple types as input. 我很早以前就用C ++编写过,但是从我记得的情况来看,
std::ofstream
非常自由,应该接受大多数简单类型作为输入。 Where's the problem? 哪里出问题了?
When, at the beginning I write HeaderFile.
在开始的时候,我写了
HeaderFile.
, It is immediately marked as error (red underline) and comment says, "Incomplete types are not allowed". ,立即将其标记为错误(红色下划线),并且注释说:“不允许使用不完整的类型”。
An observation on the 观察
"Incomplete types are not allowed"
“不允许使用不完整的类型”
. 。 error.
错误。
#include <ostream>
int main()
{
std::ofstream HeaderFile;
}
gives this error too, while this 也会给出这个错误,而这
#include <fstream>
int main()
{
std::ofstream HeaderFile;
}
compiles in VS2015. 在VS2015中编译。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.