#include <string>
#include <iostream>
using namespace std;
void main()
{
char x[8]={0};
char y[8]={0};
strncpy(x,"hello",sizeof(x));
strncpy(y,"hello world",sizeof(y));
cout<<strlen(x)<<" "<<strlen(y)<<endl;
cout<<x<<" "<<y;
}
输出:
5 13
hello hello wohello