#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char data[]={"dhewdwehkfew qwdhqwhdj qwhdwqhd"};
cout <<data<<endl;
char s1[6]="china" ,s2[3]="ch";
cout<<s1<<endl; //china
cout<<strlen(s1)<<endl; //5
cout<<sizeof(s1)<<endl; //6
strcpy(s1,s2);
cout<<s1<<endl; //ch
char arr[50]={"0X33 0X01 0X16 0X00 0X00 0X14 0X08 0X66"};
cout<<strlen(arr)<<endl;
cout<<sizeof(arr)<<endl;
char str[50];
memset(str,0,sizeof(str));
cout<<str<<endl;
cout<<arr<<endl;
strcpy(str,arr); //***************
cout<<str<<endl;
/*以下循环指出了ctrcpy的复制原理 输出结果为ch na注意中间是空格*/
for (int i=0;i<5;i++)
{
cout<<s1[i]<<endl;
}
cout<<strlen(s1)<<endl; //2
cout<<sizeof(s1)<<endl; //6
return 0;
}
----------------------------------------------------------
int copy_str(char* out, int out_size, std::string& json)
{
int json_len = json.length();
if(out_size <= json_len)
{
json_len = out_size - 1;
}
memcpy(out, json.c_str(), json_len+1);
return json_len+1;
}
dhewdwehkfew qwdhqwhdj qwhdwqhd
china
5
6
ch
39
50
0X33 0X01 0X16 0X00 0X00 0X14 0X08 0X66
0X33 0X01 0X16 0X00 0X00 0X14 0X08 0X66
c
h
i
n
a
2
6
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)