笔记

如果报文中出现0xffff的报文,则是由于有无符号的字符引起的,应该将字符改为unsigned char 类型:

class_fep_rnd &res_rnd_result;

//
 char strTmp[2048] = {0}; 
 if(res_rnd_result.res_recv_buf.length() > 0)
 {
  unsigned char str[2048] = {0};
  memcpy(str,res_rnd_result.res_recv_buf.c_str(),res_rnd_result.res_recv_buf.length());

  int cnt = 0;
  for(int i=0; i<res_rnd_result.res_recv_buf.length(); i++)
   cnt += sprintf(strTmp+cnt,"%02X ",str[i]);

  res_rnd_result.res_recv_buf = strTmp;
 }
 //

 //将std::string数组转化为字符串strTmp;

 std::string res_snd_buf= "";
 std::string tmp = "";
 obj_fep_rnd_data.GetRndDataGram(term_addr,meter_pn,meter_fn,tmp,net_str);

 //
 unsigned char str[2048] = {0};
  memcpy(str,tmp.c_str(),tmp.length());

 int cnt = 0;
 char strTmp[2048] = {0};
 for(int i=0; i<tmp.length(); i++)
  cnt += sprintf(strTmp+cnt,"%02X ",str[i]);

 res_snd_buf = strTmp;
 //

 

 //将字符串转为数组(字符串 一个字符占一个字节)

 std::string res_snd_buf = "68 42 00 42 00 16 4B 31 07 05 00 2c 61 01 01 02 03 45 16";
 std::string newstring = "";
 int len = (res_snd_buf.length()+1)/3;
 for(int i=0; i<len; i++)
 {
  std::string stmp = res_snd_buf.substr(i*3,2);
  newstring += std::strtoul(stmp.c_str(),NULL,16);
 }
 //

 

你可能感兴趣的:(c,String,null,Class)