随笔分类 -  C++

摘要:可能是编译指令加入了下面三个其中一个: -Ofast -ffast-math -ffinite-math-only 去掉上面的指令或者单独加入下面的指令均可使isnan生效。 -fno-finite-math-only 注意这个要加在最后,如果先加-fno-finite-math-only,后加-f 阅读全文
posted @ 2024-02-01 21:41 Dsp Tian 阅读(69) 评论(0) 推荐(0) 编辑
摘要:一般new出来的内存,delete掉后。 此时如果看top内存没有减少,则可以使用下面函数让系统强制回收。 #include <malloc.h> malloc_trim(0); 阅读全文
posted @ 2022-07-16 10:30 Dsp Tian 阅读(775) 评论(0) 推荐(0) 编辑
摘要:记录一下。 send.cpp: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/ipc.h> #include <s 阅读全文
posted @ 2021-11-14 23:02 Dsp Tian 阅读(922) 评论(0) 推荐(0) 编辑
摘要:如果想要在C++程序中用vector传递一个大内存,用swap是比较快的方法,不过传递之后,原始数据就不存在了。 如果后续不再使用原数据,用swap会比较好。 #include <iostream> #include <ctime> #include <vector> using namespace 阅读全文
posted @ 2021-04-25 20:47 Dsp Tian 阅读(1528) 评论(0) 推荐(0) 编辑
摘要:尝试了一下C++17的并行STL排序,速度提升比较明显。 环境是VS2019。 #include <algorithm> #include <execution> #include <iostream> #include <random> #include <chrono> using namesp 阅读全文
posted @ 2021-01-04 18:20 Dsp Tian 阅读(991) 评论(0) 推荐(0) 编辑
摘要:#include #include #include #include using namespace std; void test(int a,int b) { for (size_t i = 0; i vT; for (size_t i = 0; i < 10; i++) vT.push_back(thread(test, i,i+100)); ... 阅读全文
posted @ 2018-05-19 10:18 Dsp Tian 阅读(487) 评论(0) 推荐(0) 编辑
摘要:转自:https://blog.csdn.net/sanoseiichirou/article/details/50180533 C++标准文档——n2347(学习笔记) 链接:http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2347 阅读全文
posted @ 2018-04-13 13:12 Dsp Tian 阅读(925) 评论(0) 推荐(0) 编辑
摘要:在学习c/c++的时候,就讲到了一些C类型的字符串函数不是安全的,比如strcpy没有检查长度会溢出,推荐使用strncpy,笔试面试也经常问到。同时经常浏览安全相关的新闻,缓冲区溢出攻击是很常见的一种。那缓冲区溢出为什么可以攻击。今天通过strcpy进行简单的演示。 如下是guess_pwd.cp 阅读全文
posted @ 2017-08-27 17:07 Dsp Tian 阅读(1033) 评论(0) 推荐(0) 编辑
摘要:#include int main() { if(remove("1.txt")) printf("Could not delete the file &s \n","1.txt"); else printf("OK \n"); return 0; } 阅读全文
posted @ 2017-08-27 17:00 Dsp Tian 阅读(364) 评论(0) 推荐(0) 编辑
摘要:unsigned long get_file_size(const char *filename) { struct stat buf; if(stat(filename, &buf)<0) { return 0; } return (unsigned long)buf.st_size; } 阅读全文
posted @ 2017-08-27 16:59 Dsp Tian 阅读(375) 评论(0) 推荐(0) 编辑
摘要:不论是过去写的这个转换方法,还是今天看到的这个:string cvt2str( int x ){ int d = x; string ans = ""; while( x > 0 ) { d = x%10; ans = char(d+'0')+an... 阅读全文
posted @ 2014-07-25 14:17 Dsp Tian 阅读(922) 评论(0) 推荐(0) 编辑
摘要:类模板成员函数要不就在类模板中实现,要不就和类模板写在同一个文件中。否则然会出现下面错误:>main.obj : error LNK2019: 无法解析的外部符号 "public: int __thiscall vec::pop_back(void)" (?pop_back@?vec@H@@QAEHXZ),该符号在函数 _main 中被引用1>main.obj : error LNK2019: 无法解析的外部符号 "public: void __thiscall vec::push_back(int)" (?push_back@?vec@ 阅读全文
posted @ 2013-09-03 20:58 Dsp Tian 阅读(1942) 评论(0) 推荐(0) 编辑
摘要:总是有些小技巧需要找个地方记录的。#include <iostream> #include <ctime> #include <Windows.h>using namespace std;int main() { clock_t start,finish; start=clock(); Sleep(500); finish=clock(); double time = finish-start; cout<<"过了"<<time<<"ms"<<endl; system(& 阅读全文
posted @ 2013-03-13 17:09 Dsp Tian 阅读(678) 评论(0) 推荐(0) 编辑
摘要:#在宏中表示把参数变为字符串##在宏中表示连接两个参数#include <iostream>using namespace std;#define str(s) #s#define cons(a,b) a##bint main() { cout<<str(asfsd)<<endl; cout<<cons(1,2)<<endl; system("pause"); return 0; } 阅读全文
posted @ 2012-09-21 10:54 Dsp Tian 阅读(636) 评论(0) 推荐(0) 编辑
摘要:// overload_date.cpp// compile with: /EHsc#include <iostream>using namespace std;class Date{ int mo, da, yr;public: Date(int m, int d, int y) { mo = m; da = d; yr = y; } friend ostream& operator<<(ostream& os, const Date& dt);};ostream& operator<<(ostream& os, c 阅读全文
posted @ 2012-09-19 16:24 Dsp Tian 阅读(472) 评论(0) 推荐(0) 编辑
摘要:#include <iostream>using namespace std;class test{public: test(int a,...); ~test(); void setdata(); void showdata(); int **data; int *N; //存储每个参量的值 int n; //统计参量的个数};test::test(int a,...){ int *p=&a; n=0; while (*p!=0) { n++; p++; } data=new int... 阅读全文
posted @ 2012-09-11 14:35 Dsp Tian 阅读(418) 评论(0) 推荐(0) 编辑
摘要:/*va_list vl; //定义一个指向参数列表的变量(一个...指针)va_start(vl,first_param); //把指向参数列表的变量初始化va_arg(vl,mode); //获取下一个参数,参数类型由第二个参数指定,第二个参数用于在va_arg内部进行尺寸计算,以便找到下一个参数va_end(vl); //结束*/#include <iostream>#include <cstdarg> //头文件包含:C++ <cstdarg>; C <stdarg.h>using namespace std;void variable( 阅读全文
posted @ 2012-09-11 09:49 Dsp Tian 阅读(484) 评论(0) 推荐(0) 编辑
摘要:#include <iostream>using namespace std;int main(){ double **a; a=new double *[3]; //初始一个三行二列的矩阵 for (int i=0;i<3;i++) { a[i]=new double[2]; } a[0][0]=1; a[0][1]=2; a[1][0]=4; a[1][1]=5; a[2][0]=7; a[2][1]=8; for (int i=0;i<3;i++) { ... 阅读全文
posted @ 2012-09-10 20:26 Dsp Tian 阅读(9088) 评论(0) 推荐(0) 编辑
摘要:#include <iostream>using namespace std;int main(){ int b[]={1,2,3}; int *a; a=(int*)malloc(sizeof(int)*3); memcpy(a,b,sizeof(int)*3); for (int i=0;i<3;i++) cout<<a[i]<<""; cout<<endl; system("pause"); free(a); return 0;} 阅读全文
posted @ 2012-02-17 21:36 Dsp Tian 阅读(494) 评论(0) 推荐(0) 编辑
摘要:#include <iostream>using namespace std;void process(int *a){ a=(int*)realloc(a,sizeof(int)*4); a[3]=3;}int main(){ int *a; a=(int*)malloc(sizeof(int)*3); a[0]=0; a[1]=1; a[2]=2; process(a); for (int i=0;i<4;i++) cout<<a[i]<<""; cout<<endl; system("pause" 阅读全文
posted @ 2012-02-17 21:17 Dsp Tian 阅读(488) 评论(0) 推荐(0) 编辑

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