在C++中为char*添加char前缀的最佳方法?

Vla*_*col 0 c++ string pointers char memcpy

我需要在char*("很酷")中添加前缀('X').

做这个的最好方式是什么?

什么是最简单的方法?

char a = 'X';
char* b= " is cool";
Run Code Online (Sandbox Code Playgroud)

我需要:

char* c = "X is cool";
Run Code Online (Sandbox Code Playgroud)

到目前为止,我尝试了strcpy-strcat,memcpy;

我知道这听起来像一个愚蠢的,未经研究的问题.我想知道的是,是否有一种方法可以将char添加到数组而不将char转换为字符串.

Arn*_*rtz 6

如何使用C++标准库而不是C库函数?

auto a = 'X';
auto b = std::string{" is cool"};
b = a+b;
Run Code Online (Sandbox Code Playgroud)

或短:

auto a ='X';
auto b = a+std::string{" is cool"};
Run Code Online (Sandbox Code Playgroud)

请注意,显式强制转换为字符串.