简体   繁体   English

std :: ofstream不接受const char *作为<<运算符

[英]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.

相关问题 ofstream返回错误“没有匹配函数调用std :: basic_ofstream <char> :: close(const char [14])” - ofstream returning error “No matching function to call std::basic_ofstream<char>::close(const char [14])” 为什么&lt;&lt; ofstream in operator不是const? - Why << operator in ofstream is not const? 为什么GCC在std :: strrchr()返回值上接受从&#39;const char *&#39;到&#39;char *&#39;的转换? - Why does GCC accept convertion from 'const char *' to 'char *' on std::strrchr() returned value? 二进制&#39;[&#39;:&#39;std :: initializer_list <const char *> &#39;未定义此运算符或未转换为预定义运算符可接受的类型 - binary '[' : 'std::initializer_list<const char *>' does not define this operator or a conversion to a type acceptable to the predefined operator 错误:std :: operator &lt;&lt;中的operator &lt;&lt;不匹配 <std::char_traits<char> &gt;(**&std :: cout),(((const char *) - error: no match for operator<< in std::operator<< <std::char_traits<char> >(*&std::cout),((const char*) 为什么当使用 std::ofstream 进行二进制写入时,std::string.c_str() 不等于 const char*? - Why when use std::ofstream for binary writing, std::string.c_str() not equal const char*? 派生std :: ofstream和重载运算符&lt; - Deriving std::ofstream and overloading operator<< std :: ofstream在全局运算符中新 - std::ofstream in global operator new std :: map不接受我的运算符< - std::map does not accept my operator< std::string const&amp; 参数是否复制传递的 const char*? - Does std::string const& parameter copies the passed const char*?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM