使用“+”附加 2 个字符串时出现 C++ C2676 错误

问题描述

Error   C2676   binary '+': 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator 

我在尝试附加两个字符串时收到 C2676 错误。我已经尝试了所有我能想到的方法,但没有成功。

包含和使用代码如下。

#pragma once
#include <string>
#include <iostream>
#include <windows.h>
#include <stdlib.h>
#include <tchar.h>
#include <stream>  
#include <cstdlib>
#include <conio.h>

//#include <winnt.h>
//#include <WinUser.h>

using namespace std;
using std::string;
using std::wstring;

namespace CppCLRWinformsProjekt {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace std;

给我带来麻烦的代码是。

private: System::Void bntSelected_Click(System::Object^ sender,System::EventArgs^ e) {

    int numSelected = this->checkedListBox1->CheckedItems->Count;

    if (numSelected != 0)
    {
        // Set input focus to the list Box.
        //SetFocus(lstReceiver);
        string s = "";
        // If so,loop through all checked items and print results.  
        for (int x = 0; x < numSelected; x++)
        {
         // it appears that the first "+" sign is what is giving me trouble
        s = s + lstReceiver + (x + 1).ToString() + " = " +       this->checkedListBox1->CheckedItems[x]->ToString() + "\n";
        }
        this.lstReceiver.Items.Add(s);
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)