会员
周边
新闻
博问
闪存
众包
赞助商
YouClaw
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
首页
新随笔
管理
订阅
随笔分类 -
cpp
c++
c++文件读写
摘要:三个类: ofstream: 写文件流 ifstream: 读文件流 fstream: 读写文件流 基本使用 // basic file operations #include <iostream> #include <fstream> using namespace std; int main (
阅读全文
posted @
2022-05-25 23:05
suntus
阅读(118)
评论(0)
推荐(0)
delete this
摘要:一般不要用,用了就要注意一下几点 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
阅读(112)
评论(0)
推荐(0)
c++字符串操作
摘要: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
阅读(137)
评论(0)
推荐(0)
用到的cmake
摘要: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
阅读(64)
评论(0)
推荐(0)
vector相关
摘要: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
阅读(53)
评论(0)
推荐(0)
set相关
摘要: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
阅读(63)
评论(0)
推荐(0)
shared_from_this
摘要:1. 介绍 关于智能指针 shared_ptr 很有意思的一个问题。 可以用 std::shared_ptr 将裸指针封装起来,变成带引用计数的智能指针,当引用计数为0,C++会自动把裸指针指向的内存回收。 先定义一个类 class A { public: A(); private: int a_;
阅读全文
posted @
2021-06-26 23:39
suntus
阅读(590)
评论(0)
推荐(0)
用到的cpp-持续更新
摘要: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
阅读(55)
评论(0)
推荐(0)
公告