const char* concatenation

前端 未结 12 2191
抹茶落季
抹茶落季 2020-11-29 18:09

I need to concatenate two const chars like these:

const char *one = \"Hello \";
const char *two = \"World\";

How might I go about doing tha

12条回答
  •  情歌与酒
    2020-11-29 18:24

    If you are using C++, why don't you use std::string instead of C-style strings?

    std::string one="Hello";
    std::string two="World";
    
    std::string three= one+two;
    

    If you need to pass this string to a C-function, simply pass three.c_str()

提交回复
热议问题