随笔分类 -  cpp

c++
摘要:三个类: ofstream: 写文件流 ifstream: 读文件流 fstream: 读写文件流 基本使用 // basic file operations #include <iostream> #include <fstream> using namespace std; int main ( 阅读全文
posted @ 2022-05-25 23:05 suntus 阅读(104) 评论(0) 推荐(0) 编辑
摘要:一般不要用,用了就要注意一下几点 1. 只能用于 new 申请的对象,不能用于栈上对象 #include <iostream> class A { public: void func() { delete this; } }; int main(int argc, char const *argv[ 阅读全文
posted @ 2022-05-25 23:01 suntus 阅读(83) 评论(0) 推荐(0) 编辑
摘要:1. string转map 主要用到 std::getline() 和 std::ws #include <map> #include <string> #include <sstream> #include <iostream> std::map<std::string, std::string> 阅读全文
posted @ 2021-08-28 22:20 suntus 阅读(99) 评论(0) 推荐(0) 编辑
摘要:1. CheckCxxCompilerFlag 模块 检查cxx编译器是否支持某个flag include(CheckCxxCompilerFlag) CHECK_CXX_COMPILER_FLAG("-std=c++1" COMPILER_SUPPORTS_CXX11) if (COMPILER_ 阅读全文
posted @ 2021-08-16 11:19 suntus 阅读(43) 评论(0) 推荐(0) 编辑
摘要:1. 构造 空vector: vector(): 空vector n个元素: vector(int size): n个元素位置 vector(int size, const T &t): n个元素,均初始化为t 复制构造: vector(const vector &): 复制构造 vector(be 阅读全文
posted @ 2021-08-01 17:13 suntus 阅读(41) 评论(0) 推荐(0) 编辑
摘要:1. 定义 #include <set> template< class Key, class Compare = std::less<Key>, class Allocator = std::allocator<Key> > class set; 2. 初始化 默认构造,空set 范围构造,使用另 阅读全文
posted @ 2021-07-26 23:11 suntus 阅读(36) 评论(0) 推荐(0) 编辑
摘要:1. 介绍 关于智能指针 shared_ptr 很有意思的一个问题。 可以用 std::shared_ptr 将裸指针封装起来,变成带引用计数的智能指针,当引用计数为0,C++会自动把裸指针指向的内存回收。 先定义一个类 class A { public: A(); private: int a_; 阅读全文
posted @ 2021-06-26 23:39 suntus 阅读(562) 评论(0) 推荐(0) 编辑
摘要:C++标准保证把 std::vector 的元素排列跟数组一样,因此可以这样用: &*my_array.begin() 取到相应的数组. auto it = std::max_element(v.begin(), v.end()) 取到最大元素的iterator std::move() 将变量变为右 阅读全文
posted @ 2021-06-20 23:17 suntus 阅读(40) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示