Append to the end of a Char array in C++

前端 未结 4 1749
我在风中等你
我在风中等你 2021-02-08 14:58

Is there a command that can append one array of char onto another? Something that would theoretically work like this:

//array1 has already been set to \"The dog         


        
4条回答
  •  南笙
    南笙 (楼主)
    2021-02-08 15:32

    There's no built-in command for that because it's illegal. You can't modify the size of an array once declared.

    What you're looking for is either std::vector to simulate a dynamic array, or better yet a std::string.

    std::string first ("The dog jumps ");
    std::string second ("over the log");
    std::cout << first + second << std::endl;
    

提交回复
热议问题