C++之vector<char>与void*相互转换(八十九)
2023-09-14 09:09:57 时间
1.代码示例
#include <iostream>
#include <vector>
#include <time.h>
#include <string.h>
#include <typeinfo>
using namespace std;
void *do_work(void *buf){
//1.void* ---> vector<char*>
vector<char>* p = (vector<char>*)(buf);
printf("xxx---->%s(), line = %d, p->data() = %s, p->size() = %ld\n",__FUNCTION__,__LINE__,p->data(),p->size());
//2.void* ---> vector<char*>
vector<char>* pt = static_cast<vector<char>*>(buf);
printf("xxx---->%s(), line = %d, pt->data() = %s, pt->size() = %ld\n",__FUNCTION__,__LINE__,pt->data(),pt->size());
}
int main(){
pthread_t td;
char buffer[] = "Hello anbox.";
vector<char> data(buffer, buffer + strlen(buffer));
printf("data.data() = %s\n",data.data());
//1.vector<char> ---> void*
pthread_create(&td,NULL,do_work, (void*)(&data));
//2.vector<char> ---> void*
//pthread_create(&td,NULL,do_work, static_cast<void*>(&data));
pthread_join(td, NULL);
}
相关文章
- C++ 重载操作符与转换
- (C++)关于i++和i++的左值、右值问题
- C++进制转换
- C语言/C++基础之安得广厦千万间
- Open3D(C++) 角度制与弧度制的相互转换
- paip.c++ bcb string 转换操作大总结.
- 成功解决building ‘snappy._snappy‘ extension error: Microsoft Visual C++ 14.0 is required. Get it with “B
- c++中六种构造函数的实现以及9中情况下,构造函数的调用过程
- c++ 智能指针的向下转换 向下塑型 cast
- c++vector简单实现
- C++之非const引用无法绑定临时变量原因(一百一三十六)
- C++之const vector与vector相互转换(九十七)
- C++基础知识---static const初始化成员变量
- C++四种类型的转换
- 致C++开发者:Codespaces更新
- C++11 std::move 强制转换为右值
- C++11 noexcept修饰符与noexcept操作符
- AI机器学习模型python到C/C++的转换播
- C++ 单词转换程序
- C/C++学习笔记 各种字符转换记录
- C++快速扫盲(提升篇)
- C++ 继承与多态详解