错误C2679:二进制'+ =':找不到运算符,它采用'const char [2]'类型的右手操作数(或者没有可接受的转换)

时间:2018-04-03 08:46:57

标签: visual-c++

以下是我的C ++代码

#include "include/wpp.h"
#pragma hdrstop( "zsym/wppadb.pch")

#include "json/JsonDocument.h"

#include <string>
#include <sstream>

template <typename T>
std::wstring ToWString(T val)
{
  std::wstringstream stream;
  stream << val;
  return stream.str();
}

class CJsonDocument::Impl
{
private:
  std::wstring m_strJson;

public:
  void WriteKey(pcsz pKey) {
    m_strJson += T("\"");
    m_strJson += pKey;
    m_strJson += T("\":");
  }

  void Write(pcsz pKey, pcsz pValue = NULL){
    WriteKey(pKey);
    if( !pValue ){
      m_strJson += T('n'); m_strJson += T('u'); m_strJson += T('l'); m_strJson += T('l'); m_strJson += T(",");
    }
    else {
      m_strJson += T("\""); m_strJson += pValue; m_strJson += T("\",");
    }
  }

  void Write(pcsz pKey, sbyte btValue){
    WriteKey(pKey); m_strJson += ToWString(btValue); m_strJson += T(",");
  }

  void Write(pcsz pKey, short sValue){
    WriteKey(pKey); m_strJson += ToWString(sValue); m_strJson += T(",");
  }

  void Write(pcsz pKey, long lValue){
    WriteKey(pKey); m_strJson += ToWString(lValue); m_strJson += T(",");
  }

  void Write(pcsz pKey, nativeInt64 value){
    WriteKey(pKey); m_strJson += ToWString(value); m_strJson += T(",");
  }

  void BeginObject(pcsz pKey = NULL){
    if( pKey ) WriteKey(pKey);
    m_strJson += T("{");
  }

  void EndObject(int bHasNext = 0){
    // remove the last comma
    int iLast = m_strJson.size() - 1;
    if( m_strJson.at(iLast) == T(',') )
      m_strJson.at(iLast) = T('}');
    else
      m_strJson += T("}");

    if( bHasNext ) m_strJson += T(",");
  }

  void BeginArray(pcsz pKey = NULL){
    if( pKey ) WriteKey(pKey);
    m_strJson += T("[");
  }

  void EndArray(int bHasNext = 0){
    // remove the last comma
    int iLast = m_strJson.size() - 1;
    if( m_strJson.at(iLast) == T(',') )
      m_strJson.at(iLast) = T(']');
    else
      m_strJson += T("]");

    if( bHasNext ) m_strJson += T(",");
  }

  CString String() const {
    return m_strJson.c_str();
  }
};

一开始代码没有问题,直到我重新安装系统,开发环境是win 10,IDE是VS 2013.这是一个编译错误。我已经尝试在头部添加#include <iostream>但没用。

Error   4   error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'const char [2]' (or there is no acceptable conversion)   c:\am-workspace\am-cpp\wppdev\json\jsondocument.cpp 34  1   am
Error   5   error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'pcsz' (or there is no acceptable conversion) c:\am-workspace\am-cpp\wppdev\json\jsondocument.cpp 35  1   am
Error   6   error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'const char [3]' (or there is no acceptable conversion)   c:\am-workspace\am-cpp\wppdev\json\jsondocument.cpp 36  1   am
Error   7   error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'const char [2]' (or there is no acceptable conversion)   c:\am-workspace\am-cpp\wppdev\json\jsondocument.cpp 42  1   am
Error   8   error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'const char [2]' (or there is no acceptable conversion)   c:\am-workspace\am-cpp\wppdev\json\jsondocument.cpp 45  1   am
Error   9   error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'pcsz' (or there is no acceptable conversion) c:\am-workspace\am-cpp\wppdev\json\jsondocument.cpp 45  1   am
Error   10  error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'const char [3]' (or there is no acceptable conversion)   c:\am-workspace\am-cpp\wppdev\json\jsondocument.cpp 45  1   am
Error   11  error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'const char [2]' (or there is no acceptable conversion)   c:\am-workspace\am-cpp\wppdev\json\jsondocument.cpp 50  1   am
Error   12  error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'const char [2]' (or there is no acceptable conversion)   c:\am-workspace\am-cpp\wppdev\json\jsondocument.cpp 54  1   am
Error   13  error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'const char [2]' (or there is no acceptable conversion)   c:\am-workspace\am-cpp\wppdev\json\jsondocument.cpp 58  1   am
Error   14  error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'const char [2]' (or there is no acceptable conversion)   c:\am-workspace\am-cpp\wppdev\json\jsondocument.cpp 62  1   am
Error   15  error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'const char [2]' (or there is no acceptable conversion)   c:\am-workspace\am-cpp\wppdev\json\jsondocument.cpp 67  1   am
Error   16  error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'const char [2]' (or there is no acceptable conversion)   c:\am-workspace\am-cpp\wppdev\json\jsondocument.cpp 76  1   am
Error   17  error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'const char [2]' (or there is no acceptable conversion)   c:\am-workspace\am-cpp\wppdev\json\jsondocument.cpp 78  1   am
Error   18  error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'const char [2]' (or there is no acceptable conversion)   c:\am-workspace\am-cpp\wppdev\json\jsondocument.cpp 83  1   am
Error   19  error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'const char [2]' (or there is no acceptable conversion)   c:\am-workspace\am-cpp\wppdev\json\jsondocument.cpp 92  1   am
Error   20  error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'const char [2]' (or there is no acceptable conversion)   c:\am-workspace\am-cpp\wppdev\json\jsondocument.cpp 94  1   am

我搜索了许多类似的解决方案但不适合我。 我将光标放在提示上,错误为Error:no operator"+=" matches these operands operand types are: std::wstring += const char [2]

0 个答案:

没有答案