输出有乱码,涉及与C字符串相关的标准库函数
/* Windows7,CodeBlocks13.12 */
#include <iostream>
#include <cstring> //strcat, strchr, strcpy, strstr
using std::cout;
using std::endl;
int main()
{
char head[]="You can ";
char tail[]="a can?";
char* question=strcat(head, tail);
cout<<question<<endl; //输出"You can a can?",与期望一样
char* half=strchr(question, 'n');
cout<<half<<endl; //期望输出"n a can?",但输出"n a can乱码"
char backhalf[10];
strcpy(backhalf, half);
cout<<backhalf<<endl; //期望输出"n a can?",但输出"n a can乱码"
char* behind=strstr(question, "can");
cout<<behind<<endl; //期望输出"can a can?",但输出"can a乱码"
return 0;
}