STL : std::string可以当UCHAR数组用
来源:互联网 发布:漱口水0知乎 编辑:程序博客网 时间:2024/04/29 02:19
// testWin32Console.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <Windows.h>#include <tchar.h>#include <string>void fnTest();int _tmain(int argc, _TCHAR* argv[]){ fnTest(); /// run result /** strBufSrc.size() = 260 strBufDst.size() = 260 verify ok, std::string can use as binary array */ /// 通过试验,可以看出 std::string 可以当二进制数组用getwchar();return 0;}void fnTest(){ /// 在一个工程中看到用std::string resize + memcpy 当二进制数组用 /// 当需要赋值到另外一个string时,是采用原生的'= '操作符,还是自己拷贝呢 /// 如果自己(resize + memcpy)拷贝的话,是可以的 /// 如果用 '=' 操作符, 不能确定, 验证一下 size_t nIndex = 0; std::string strBufSrc = ""; std::string strBufDst = ""; UCHAR uBuf[MAX_PATH] = {'\0'}; /// 对uBuf赋值,模拟是一个二进制文件的内容 for (nIndex = 0; nIndex < sizeof(uBuf); nIndex++) { uBuf[nIndex] = (0xff - nIndex) % 0xff; ///< 255 ~ 1 } /// 对src赋值 strBufSrc.resize(sizeof(uBuf)); ::memcpy((PVOID)strBufSrc.data(), uBuf, sizeof(uBuf)); /// 用src对dst赋值 strBufDst = strBufSrc; _tprintf(L"strBufSrc.size() = %d\r\n", strBufSrc.size()); _tprintf(L"strBufDst.size() = %d\r\n", strBufDst.size()); if (strBufDst.size() != strBufSrc.size()) { _tprintf(L"verify failed, can't use std::string as binary array by \"=\"\r\n"); return; } else { /// 逐个字节验证,看是否相同 for (nIndex = 0; nIndex < strBufSrc.size(); nIndex++) { if (strBufSrc[nIndex] != strBufDst[nIndex]) { /// failed _tprintf(L"failed : nIndex = %d, src char[0x%X] <=> dst char[0x%X]\r\n"); return; } } } _tprintf(L"verify ok, std::string can use as binary array\r\n");}
0 0
- STL : std::string可以当UCHAR数组用
- C++ STL : std::string
- 入门计划->学用stl std::map<std::string, int>
- std::string and stl 算法
- std::string and stl 算法
- 如何把std::string当char *使用?
- 将std::string当字节流使
- C++/STL std::string 的用法
- stl 中std::string 的方法
- STL std::string 字符全局替换
- 用char数组模拟STL之string
- std stl
- STL中的std::string与Unicode的使用
- VC中STL std::string类的使用
- VC中STL std::string类的使用 .
- STL 库其中的 std::string用法总结
- DLL中传递STL参数(std::string传引用崩溃)
- 用std::string取代char*
- 【Git】git add -A = git add . + git add -u
- 编辑文章 - 博客频道 - CSDN.NET
- 客户端工具远程连接oracle
- Head First设计模式C++实现--第一章:策略模式
- 算法->《编程之美》2.18——数组分割新思路(包含分类后数组的输出)
- STL : std::string可以当UCHAR数组用
- Block高级用法(传值)
- java学习笔记(4)
- 创建你第一个SharePoint 2010 应用程序----完整推荐总结
- jqm视频播放器,html5视频播放器,html5音乐播放器,html5播放器,video开发demo,html5视频播放示例,html5手机视频播放器
- A
- Ruby Regexp using gsub is there an equivalent to self keyword?
- SVN update Failed . Locked
- Beginning Python Chapter 27