Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c++;类型为';字符*';和';常量字符[2]';到二进制';操作员+';_C++_Visual Studio 2010_Char_Constants - Fatal编程技术网

C++ c++;类型为';字符*';和';常量字符[2]';到二进制';操作员+';

C++ c++;类型为';字符*';和';常量字符[2]';到二进制';操作员+';,c++,visual-studio-2010,char,constants,C++,Visual Studio 2010,Char,Constants,尝试执行以下简单代码时,编译器将错误“类型为'char*'和'const char[2]'的操作数无效”返回给二进制“operator+”: BodyText[client] = PS3::ReadString(0x0178646c) + "\n" ; 下面是我的ReadString()函数: char returnRead[100]; char* ReadString(int address) { memset(&returnRead[0], 0, sizeof(return

尝试执行以下简单代码时,编译器将错误“类型为'char*'和'const char[2]'的操作数无效”返回给二进制“operator+”:

BodyText[client] = PS3::ReadString(0x0178646c) + "\n" ;
下面是我的ReadString()函数:

char returnRead[100];
char* ReadString(int address)
{
    memset(&returnRead[0], 0, sizeof(returnRead));
    int strlength = 100;
    char* StrBytes = ReadBytes(address, strlength);
    for (int i = 0; i < strlength; i++)
    {
        if (StrBytes[i] != 0x00)
            returnRead[i] = StrBytes[i];
    else
        break;
}
return returnRead;
}
charreturnread[100];
char*ReadString(int地址)
{
memset(&returnRead[0],0,sizeof(returnRead));
int strlength=100;
char*StrBytes=ReadBytes(地址,strlength);
对于(int i=0;i

无论如何,感谢您阅读这是因为
char*
(函数的返回类型)和
const char[2]
(类型为
“\n”
)没有
运算符+
,而且由于您无法为内置类型重载运算符,因此也就没有了。因为这个问题被标记为C++:

只要使用
std::string
而不是
char*
,您的所有问题都已经解决了<代码>标准::字符串
将优于您尝试使用的黑客


您可以找到有关
字符串的概述
功能以及如何使用它们的示例。然后可以将字符串
a、b、c
连接起来,就像
std::string new\u string=a+b+c

不能将C样式字符串与
+
连接起来。使用<代码> STD::String 。这不是一个坏问题,字符串在C++中是不容易的/直觉的。只有使用C++作为C类的人才会遇到这样的问题。(好吧,如果你必须在标准库上实现,也许,但这是世界范围内的几个家伙。)解决这个问题:std::string x=PS3::ReadString(0x0178646c)+“\n”+PS3::ReadString(0x178BC74)+“\n”+PS3::ReadString(0x179147C)+“\n”+PS3::ReadString(0x1796C84)+“\n”抱歉,我太笨了。我如何连接它?我尝试了:std::string x=“\n”;char*y=PS3::ReadString(0x0178646c);std::strcpy(y,x.c_str());删除[]y;如果您可以更改
ReadBytes
,让它返回一个
std::string
,暂时忘记
char*
memset
fscanf
以及所有这些C风格的东西。这是不必要的困难得到正确的,并没有利于你。