小编Lợi*_*yễn的帖子

为什么C++中有些字符无法编辑?

我正在尝试strcat用 C++ 编写自己的函数,但它有一些问题。
\n我的输入是两个字符c和,我的函数将返回一个指向与 相连的a字符的字符指针。ca

\n

例如,
\n输入:\'abc\' \'xyz\'
\n预期输出:\'xyzabc\'
\n我的函数的输出:\'xyza@\xe2\x96\xb2\xe2\x88\xa9\'

\n

我的函数返回一些与我的输入不同的特殊字符。

\n

我调试了我的函数并发现:

\n
    \n
  • 当 时i=0destination[3]= source[0]=\'a\'
  • \n
  • 但当i=1, destination[8]= source[1]=\'b\'
  • \n
  • i=2, destination[9]= source[2]=\'c\'
  • \n
  • 最后,destination[10]=\'\\0\'
  • \n
\n
#include<iostream>\n#include<string.h>\nusing namespace std;\n\nchar* mystrcat ( char * destination, const char *source){\n    for (int i=0; i<strlen(source); i++) {\n        destination[strlen(destination)+i] …
Run Code Online (Sandbox Code Playgroud)

c++ string strcat

7
推荐指数
1
解决办法
204
查看次数

标签 统计

c++ ×1

strcat ×1

string ×1