C++ std::string与char[]的互转

C++ std::string与char[]的互转

  • [1 char[]转std::string](#1 char[]转std::string)
  • [2 std::string转char[]](#2 std::string转char[])

1 char[]转std::string

cpp 复制代码
char arry[5] = {0x03,0xaf,0x34,0x65,0x55};
//方法1
std::string strArry(arry);
//方法2
std::string strArry(arry,sizeof(arry));

2 std::string转char[]

cpp 复制代码
std::cout << "hex:" << std::hex;
char* bytes = new char[strArry.length()+1];
std::strcpy(bytes, strArry.c_str());
for (int i = 0; i < strArry.length(); i++)
	std::cout << (bytes[i] & 0xff);
std::cout << std::dec << std::endl;
相关推荐
karmueo462 小时前
视频序列和射频信号多模态融合算法Fusion-Vital解读
算法·音视频·多模态
小汉堡编程3 小时前
数据结构——vector数组c++(超详细)
数据结构·c++
写代码的小球5 小时前
求模运算符c
算法
weixin_472339465 小时前
高效处理大体积Excel文件的Java技术方案解析
java·开发语言·excel
枯萎穿心攻击6 小时前
响应式编程入门教程第二节:构建 ObservableProperty<T> — 封装 ReactiveProperty 的高级用法
开发语言·unity·c#·游戏引擎
Eiceblue7 小时前
【免费.NET方案】CSV到PDF与DataTable的快速转换
开发语言·pdf·c#·.net
tan180°8 小时前
MySQL表的操作(3)
linux·数据库·c++·vscode·后端·mysql
m0_555762908 小时前
Matlab 频谱分析 (Spectral Analysis)
开发语言·matlab
大千AI助手8 小时前
DTW模版匹配:弹性对齐的时间序列相似度度量算法
人工智能·算法·机器学习·数据挖掘·模版匹配·dtw模版匹配