简体   繁体   English

'const char [18]' 和 'const char*' 类型的无效操作数到二进制 'operator

[英]invalid operands of types ‘const char [18]’ and ‘const char*’ to binary ‘operator

Im new to c++ so not sure where i miss out its as only the description not allowing execute the code, hope able to help我是 c++ 的新手,所以不确定我在哪里错过了它,因为只有描述不允许执行代码,希望能有所帮助

    InventoryItem (char const *desc, double c, int u)
    {
     description = new char[strlen (desc) + 100];

      strcpy (description, desc);

   ~InventoryItem ()
    {
      delete[]description;
     }

      const char *getDescription () const
     {
    return description;
     }


     cout << setprecision (2) << fixed << showpoint;

      cout < "Item Description:" << stock.getDescription ()<< endl;

You wrote cout < on the last line, where you should have cout << .你在最后一行写了cout < ,你应该有cout <<

I'm assuming the message said operator << ;我假设消息说operator << ; C++ interpreted it as comparing cout to "Item description:" << stock.getDescription() << endl , but "Item description:" << stock.getDescription()" by itself doesn't make sense, so it gave an error. C++ 将其解释为将cout"Item description:" << stock.getDescription() << endl进行比较,但"Item description:" << stock.getDescription()"本身没有意义,因此它给出了错误.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 二进制“ operator +”类型为“ const char [8]”和“ const char *”类型的无效操作数 - Invalid operands of types ‘const char [8]’ and ‘const char*’ to binary ‘operator+ &#39;const char*&#39; 和 const char[4]&#39; 类型的无效操作数到二进制 &#39;operator+&#39; - invalid operands of types 'const char*' and const char[4]' to binary 'operator+' 无效的 char 和 const char[2] 类型的操作数到二元运算符 - Invalid Operands of types char and const char[2] to binary operator 类型为&#39;int&#39;和&#39;const char [15]&#39;的无效操作数为二进制&#39;operator &lt;&lt;&#39;^ - invalid operands of types ‘int’ and ‘const char [15]’ to binary ‘operator<<’ ^ 二进制“ operator!=” |的类型为&#39;double&#39;和&#39;const char [2]&#39;的无效操作数 - Invalid operands of types 'double' and 'const char [2]' to binary 'operator!='| 'int' 和 'const char [11]' 类型的无效操作数到二进制 'operator&lt;&lt;' - invalid operands of types 'int' and 'const char [11]' to binary 'operator<<' 类型为“ double”的无效操作数snd const char [3]”转换为二进制“ operator &lt;&lt;” - invalid operands of types ‘double’ snd const char [3]’ to binary 'operator<<' 错误:类型为&#39;const char [3]&#39;和&#39;int *&#39;的无效操作数为二进制&#39;operator *&#39; - Error: invalid operands of types 'const char [3]' and 'int*' to binary 'operator*' “错误:二进制&#39;operator &lt;&lt;&#39;|的类型为&#39;int&#39;和&#39;const char [2]&#39;的无效操作数” - “error: invalid operands of types 'int' and 'const char [2]' to binary 'operator<<'|” 错误:类型&#39;const char [8]&#39;和&#39;const char [17]&#39;到二进制&#39;operator &lt;&lt;&#39;的操作数无效 - error: invalid operands of types 'const char[8]' and 'const char [17]' to binary 'operator<<'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM