我正在尝试将一个 unsigned char
连接到一个 std::string
但它给我一个错误提示“operator+
not defined”
#include <string>
int main()
{
unsigned char a = 't';
std::string s = "uoyriri";
s = s + a; // error: no match for operator
}
最佳答案
std::string
没有 char
的 operator+
重载。您可以执行以下操作:
s += 't';
但一般来说,您可能想要的是 std::stringstream
:
std::stringstream ss;
ss << "uoyriri";
ss << a;
ss.str(); // The resulting string
关于c++ - 如何将 `unsigned char` 连接到 `std::string` ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9350703/