const char* concatenation

前端 未结 12 2171
抹茶落季
抹茶落季 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:36

    It seems like you're using C++ with a C library and therefore you need to work with const char *.

    I suggest wrapping those const char * into std::string:

    const char *a = "hello "; 
    const char *b = "world"; 
    std::string c = a; 
    std::string d = b; 
    cout << c + d;
    

提交回复
热议问题