C++
文章平均质量分 52
腾阳山泥若
简单记录开发中遇到的问题,方便快速查找
展开
-
win10+VS2017安装PCL库
参考博客https://www.jianshu.com/p/463f54c91ab7https://blog.csdn.net/weixin_41991128/article/details/83864713可能出现的问题:使用VS2017编写程序出现C4996错误在代码头部加入下面语句:#define _CRT_SECURE_NO_DEPRECATE#pragma warning(disable:4996)编译代码出现由于找不到OpenNI2.dll,无法继续执行代码。重新安装程序可能原创 2021-01-23 12:11:00 · 314 阅读 · 0 评论 -
【Union联合】
C++的联合是一个特殊的类,联合中可以有多个数据成员,但是在任意时刻只能有一个数据成员有值,例如下列联合中有三个数据成员,其中占位最大的是a,因此该联合的所占的大小为32位union Demo{ int 32_t a; int 16_t b; int 16_t c;};每一时刻只能有一个成员有值,其它成员处于未定义的状态,例如,进行下列赋值Demo demo;demo.a = 0x08172017;此时demo所在内存的内容为7102 1780,而demo.b和demo.c原创 2020-08-22 22:02:48 · 143 阅读 · 0 评论 -
【STL】vector简单使用
参考需要头文件#include<iostream>#include<vector>using namespace std;尾部添加元素push_backvector<int> vec;// insert valuefor (int i = 0; i < 5; i++) vec.push_back(10 * (i + 1));输出元素 直接当初数组进行输出vector<int> vec;// push back valuefo原创 2020-07-14 19:50:58 · 90 阅读 · 0 评论 -
【C++】程序计时
#include<iostream>#include<ctime>using namespace std;int main() { clock_t start, end; start = clock(); // task code end= clock(); double endtime = (double)(end - start) / CLOCKS_PER_SEC; cout << "Total time:" << endtim原创 2020-07-01 10:24:47 · 102 阅读 · 0 评论 -
【C++】文件读写指针定位
主要函数:指针定位函数SetFilePointer,读文件ReadFile,写文件WriteFile。首先使用CreateFile创建文件,SetFilePointer函数将指针定位到文件指定位置(tail),从这个位置开始调用WriteFile函数写入内容(text);同理可将指针定位到指定位置,从这个位置开始调用ReadFile函数读取指定长度的内容。#include<iostream>#include<string>#include <fstream>us原创 2020-06-30 09:09:41 · 2721 阅读 · 0 评论 -
Visual Studio解决const char *与LPCWSTR 不兼容
项目->属性->配置属性->高级,将字符集改为未设置原创 2020-06-29 23:07:20 · 2091 阅读 · 0 评论 -
【string】字符串转int stoi
使用stoi函数将字符串转为int型,需要 #include<string>char chs[] = "123";int x = stoi(chs);cout << x << endl;123原创 2020-06-29 11:46:57 · 328 阅读 · 0 评论 -
【string】字符串分割strock
使用strock将字符串按特定分隔符分割#include<iostream>#include<string>using namespace std;int main(){ char sentence[] = "0+&+15+&+A B C D E"; cout << sentence << endl; char* tokenPtr = strtok(sentence, "+&+"); while (tokenPtr !原创 2020-06-29 11:42:18 · 305 阅读 · 0 评论 -
【C++】string、char*互相转换
string 2 char*c_str()方法返回一个const char* 类型的指针变量,使用strcpy函数copystring str = "abcs";char* chs = new char[str.length()+1];strcpy(chs, str.c_str());cout << chs << endl;(const) char* 2 stringconst char 或 char 转换为stringchar chs[] = "char str"原创 2020-06-29 11:14:40 · 259 阅读 · 0 评论 -
【string】int转string to_string
使用to_string函数将整型变量转为字符串。int n = 10;string str = to_string(n);原创 2020-06-29 10:15:32 · 105 阅读 · 0 评论 -
【string】获取字符串长度strlen
char str[] = "abc";cout << strlen(str) << endl;3原创 2020-06-28 22:05:46 · 313 阅读 · 0 评论 -
【string】字符串拷贝strcpy
strcpy即string copychar* str = new char[5];strcpy(str, "Hello");原创 2020-06-28 22:00:57 · 652 阅读 · 0 评论 -
【STL】map基本用法
C++中的map类似于python中的字典,形如<key,value>对创建map对象#include <stdio.h>#include <map>map<string, int> IDMAP;IDMAP["ID_0001"] = 1;IDMAP["ID_0002"] = 2;IDMAP["ID_0003"] = 3;// 遍历map<string, int>::iterator iter;for (iter = IDMAP原创 2020-06-28 20:26:56 · 127 阅读 · 0 评论 -
【C++】Socket通信例子
锁定原创 2020-06-27 10:55:29 · 209 阅读 · 0 评论