C/C++
idealcitier
https://gitee.com/idealcitier
展开
-
delete a mutex while it is locked
[1] https://stackoverflow.com/questions/34030156/deleting-a-mutex-that-is-locked[2] https://en.cppreference.com/w/cpp/thread/mutex/~mutex原创 2023-02-03 10:02:33 · 168 阅读 · 1 评论 -
visit
【代码】visit。原创 2022-10-13 19:41:17 · 78 阅读 · 0 评论 -
C语言嵌入汇编Extended ASM
Extended ASM在程序中可能需要对寄存器进行操作,而使用C/C++无法直接对寄存器进行操作,这就要用到嵌入汇编。基本语法嵌入汇编的基本语法如下:asm asm-qualifiers ( "AssemblerTemplate" // 汇编指令,使用\n分割,可写多行 : OutputOperands // 输出 : InputOperands // 输入 : Clobbers // 汇编代码更改的寄存器,使用','分割,具原创 2022-05-10 23:20:11 · 409 阅读 · 0 评论 -
dlopen 和函数属性 __attribute__((constructor))& __attribute__((destructor))
dlopen 和函数属性 attribute((constructor))& attribute((destructor))Shared objects may export functions using the__attribute__((constructor)) and __attribute__((destructor))function attributes. Constructor functions are executed beforedlopen() returns,原创 2022-01-18 11:51:42 · 749 阅读 · 0 评论 -
c++ string bugfix
#include <iostream>#include <algorithm>#include <string>#include <vector>std::vector<std::string> spiltStringBySemicilon(std::string str) { std::vector<std::string> eles; while (int pos = str.find(";") != st原创 2021-12-27 15:46:51 · 452 阅读 · 0 评论 -
删除string首尾以及中间的空格
删除string首尾以及中间的空格对char*字符串进行操作,删除其中的空格,十分的繁琐。若代码为c++代码可以借助标准库算法,可对字符串首尾以及中间的空格进行删除。#include <iostream>#include <algorithm>#include <string>int main() { std::string content = " 11223 3344 "; content.erase(remove(content.b原创 2021-12-27 14:57:08 · 693 阅读 · 0 评论 -
string&c_str()的使用
C语言中对字符串(char*)操作的方法较少,在c++ 中可将(char*)转换为string类进行操作。c++中可使用的c_str() 方法将string转换为const char *。 但使用该方法要注意使用场合,如使用不当,极易出现各种问题。#include <iostream>#include <string>using namespace std;const char *GetName(const char *nameAndID) { if (nameAnd原创 2021-12-23 21:27:34 · 562 阅读 · 0 评论 -
迭代过程中删除指定元素
迭代过程中删除指定元素总结4中在迭代过程删除list中指定元素方法1#include <iostream>#include <list>using namespace std;int main() { list<int> lst = {1,2,3,4,5}; auto it = lst.begin(); while(it != lst.end()) { if (*it == 4) { it =原创 2021-12-11 15:01:08 · 857 阅读 · 0 评论 -
atexit,exit
exit任何一个线程调用exit都会导致进程结束(进程一旦结束,进程中的所有线程都会结束)atexit通过atexit注册的方法,可以在程序正常退出(exit)时进行执行。注册的方法为无参数、无返回值的方法。atexit最多可以注册32个方法。exit函数调用后,执行顺序和注册的顺序相反,也就是说最后注册的方法先执行。同一个方法注册多次会执行多次demo// gcc demo.cpp -lpthread#include<pthread.h>#include<std原创 2021-06-18 15:40:06 · 108 阅读 · 0 评论 -
c++单例模式
#include <iostream>using namespace std;class Singleton{public: static Singleton &GetSingleton() { static Singleton instance; return instance; } void Print() { std::cout << "我的实例内存地址是:" << this &原创 2020-08-17 19:21:24 · 86 阅读 · 0 评论 -
c++长字符串换行
#include<iostream>using namespace std;int main(){ string str1 = "congrat" "ulation"; string str2 = "congrat" \ "ulation"; string str3 = "congrat \ ulation"; cout << str1原创 2020-07-28 10:31:04 · 1009 阅读 · 0 评论 -
[flag] c++ 花式打印
#include<iostream>using namespace std;std::ostream &log() { return std::cout;}int main() { string str; log() << "hello"; return 0;}原创 2020-07-27 21:04:14 · 245 阅读 · 0 评论 -
aoti使用注意,越界问题以及Segmentation fault问题
官方解释:Interprets an integer value in a byte string pointed to by str.Discards any whitespace characters until the first non-whitespace character is found, then takes as many characters as possible to form a valid integer number representation and convert原创 2020-06-19 20:24:57 · 953 阅读 · 1 评论 -
C/C++ 返回局部变量-error
还是举一个例子,将str = strTmp 掉,对比前后输出的变化。#include <iostream>#include <string>#include <vector>using namespace std;void foo(char **str) { char *strTmp[4] = {nullptr}; strTmp[0] = reinterpret_cast<char *>('a'); str = strTmp原创 2020-06-13 12:00:41 · 198 阅读 · 0 评论 -
static关键字
#include <iostream>using namespace std;void fn();int main(){ fn(); fn(); fn();}void fn(){ static int n = 10; cout << n << endl; n++;}101112原创 2020-06-03 19:32:59 · 111 阅读 · 1 评论 -
static_cast 和 reinterpret_cast区别
C++中类型之间的转换,可以分为隐式类型转换和显式类型转换隐式类型转换是自动执行的,无需显式的进行操作。 隐式类型转换发生在很多地方,比如函数实参到形参的类型转换、函数返回值类型的自动转换,在此不进行进一步的介绍。C++ 提供四种转换操作符来实现显式类型转换(强类型转换),static_cast, reinterpret_cast, const_cast 和 dynamic_castconst_cast 和 dynamic_cast后面的两种中,const_cast用于去除除对象的const或者vo原创 2020-05-25 15:04:12 · 598 阅读 · 0 评论 -
string&vector 用法
string获取长度str.size()判空str.empty()在str字符串尾部插入str.append("str")在str字符串头部添加str.inster(0, "str")删除str尾部的字符str.pop_back()数字转字符串to_string(num)清空字符串str.clear()String demo#include <iostream...原创 2020-04-13 21:52:46 · 163 阅读 · 0 评论 -
string的find 方法 c++
string的find 方法 c++string (1)size_t find (const string& str, size_t pos = 0) const noexcept;c-string (2)size_t find (const char* s, size_t pos = 0) const;buffer (3)size_t find (cons...原创 2019-12-09 23:44:03 · 1521 阅读 · 0 评论 -
C++实现string的spilt功能-temp
C++的string没有spilt的功能,本文通过使用Sting的find和substr方法实现spilt的功能#include <iostream> ...原创 2019-07-25 23:41:19 · 813 阅读 · 3 评论 -
函数声明(Function Declaration)和函数原型(Function Protostyle)
今天在看C++ prime plus,注意这个plus。在此,给出个人对这本书的建议,假若个人有一定的编程经验想学习C++的,强烈推荐C++ prime这本书,注意后面没有plus。回归正题,简单的说一下所谓的函数声明和函数原型。关于函数声明和函数原型有什么区别呢?在网上查阅了大量的中文博客,也没有说明两者具体区别,但是标题依旧是两者的区别。在此贴上知乎上谭叙的讲解。函数原型在c++中就...原创 2019-05-22 23:29:29 · 1945 阅读 · 3 评论 -
08-float和double
float和double的区别这两个浮点类型经常进行使用,但是两者的区别一直进行混淆,通过本文来记录一下。首先来记录一个最基本的概念byte和bit英文中文转换byte字节8bitbit位1 bitbit是计算机最小单位。double和float在内存中占有的字节数不同数据类型所占空间单精度浮点数 float4byte...原创 2019-05-12 20:57:31 · 192 阅读 · 0 评论