加入两个Char *

时间:2014-01-14 11:54:31

标签: c++

我有以下声明,我想要做的是将变量消息设置为等于它自己加上数据  message = message + data

我该怎么做?我还是C ++的新手

void DataLog::log(char* data)
 {
struct sockaddr_in si_other;
    int s, slen=sizeof(si_other);
    char buf[BUFLEN];
    char* message;
    WSADATA wsa;
    ...
}

2 个答案:

答案 0 :(得分:4)

strcat 是要走的路。

但是,当您使用c ++时,请更好地使用std::string代替char*

使用std::string

您只需添加两个strings +运算符。

答案 1 :(得分:0)

如果我理解正确,这将是一种方法:

void DataLog::log(char* data)
 {
    ...
    std::string message (buf); //or whatever you use to initialize the message
    message.append (data); //the second part of the message
}