#include <iostream> #include <string> #include <windows.h> using namespace std; bool str_cat(char* dest, int len, const char* st1, const char* st2) { int pos = 0; if (!dest || len < 1) return false; if (st1) { while (*st1 && pos < (len - 1)) { *(dest + pos) = *st1; pos++; st1++; } } if (st2) { while (*st2 && pos < (len - 1)) { *(dest + pos) = *st2; pos++; st2++; } } *(dest + pos) = '\0'; return true; } int main() { const char* st1 = "我是"; const char* st2 = "小萌新"; char dest[64]; str_cat(dest, 64, st1, st2); cout << "dest:" << dest << endl; system("pause"); return 0; }标签:函数,dest,pos,char,st1,st2,字符串,指针 From: https://www.cnblogs.com/smartlearn/p/16772730.html