微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决使用“+”附加 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 举报,一经查实,本站将立刻删除。