随笔分类 -  C++

摘要:C++流## C++中流的概念 在程序设计中,数据输入输出(I/O)操作是必不可少的,C++语言的数据输入/输出操作时通过I/O流库来实现的。C++中把数据之间的传输操作称为流,流既可以表示数据从内存传送到某个载体或设备中,即输出流,也可以表示数据从某个载体或设备传送到内存缓冲区变量中,即输入流。 C++中 阅读全文
posted @ 2023-08-09 16:29 何太狼 阅读(194) 评论(0) 推荐(0)
摘要:C++Bug记录七月 2023/7/23 terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc 开动态数组的时候参数为一个负值或其他一些奇怪的值 2023/7/25 运行时自动跳转到new_all 阅读全文
posted @ 2023-07-23 17:54 何太狼 阅读(35) 评论(0) 推荐(0)
摘要:对拍对拍是什么 当我们需要测试自己代码的正确性,或者需要能找到bug的样例,就可以用到对拍。对拍需要两份代码,一份是正确的(可以不是正解,但要保证正确性),另一份是自己的代码,然后生成随机数据让两份代码根据同一份输入一起运行比较结果,以此来检验自己代码的正确性。 对拍实现 以下用前缀和问题演示对拍。 首 阅读全文
posted @ 2023-05-02 15:33 何太狼 阅读(140) 评论(0) 推荐(0)
摘要:cout cincin istream类,定在文件为iostream头文件,为以下数据类型重载了>>抽取操作符,所重载的函数称为格式化输入函数。 signed char &、unsigned char &、char &、short &、unsigned short &、int &、unsigned int &、lo 阅读全文
posted @ 2023-05-02 15:20 何太狼 阅读(61) 评论(0) 推荐(0)
摘要:C++ 随机数生成器 mt19937以下代码来自官方示例 // mersenne_twister_engine constructor #include <iostream> #include <chrono> #include <random> int main () { // obtain a seed from the syst 阅读全文
posted @ 2022-12-19 21:07 何太狼 阅读(431) 评论(0) 推荐(0)
摘要:C++ sortsort是C++ STL(Standard template library)提供的排序函数,它可以为普通函数或者容器中指定范围内的元素进行排序。默认为升序排序,排序的区间左闭右开。 使用标准库(STL)提供的比较规则 vector<int> a(n); //.... sort(a.begin(), 阅读全文
posted @ 2022-12-13 21:35 何太狼 阅读(176) 评论(0) 推荐(0)
摘要:#include <bits/stdc++.h> using namespace std; class Out { public: int i, j; Out() { i = 1; j = 2; in = new In; in->out = this;//初始化外部类的时候设置内部类的指针 } vo 阅读全文
posted @ 2022-11-06 18:53 何太狼 阅读(597) 评论(0) 推荐(0)
摘要:#include <bits/stdc++.h> using namespace std; int main() { int n = 5, t; vector<int> a, b; for (int i = 0; i < n; ++i) { scanf("%d", &t); a.push_back( 阅读全文
posted @ 2022-10-29 19:52 何太狼 阅读(38) 评论(0) 推荐(0)
摘要:ios::sync_with_stdio(false); 解除同步之后就不要混用scanf与cin了。 cin.tie(0),cout.tie(0); 解除cin,cout的绑定。cin与cout的绑定多用在重定向中,竞赛中可直接解除。 阅读全文
posted @ 2022-08-02 21:48 何太狼 阅读(599) 评论(0) 推荐(0)
摘要:计算x的y次幂,x,y及返回的结果都为浮点数。 需要注意的是当x为负数及y为小数发生错误。 当x为0且y小于0发生错误。 阅读全文
posted @ 2022-07-21 11:46 何太狼 阅读(89) 评论(0) 推荐(0)
摘要:#cin.getline(name,ArSize) name为数组名,ArSize为要读取的字符数,该函数最多读入的字符数为ArSize-1,读到换行符时停止并丢弃换行符。 #cin.get(name,ArSize) 与cin.getline()的区别为cin.get()会将换行符留在输入队列中。 阅读全文
posted @ 2022-05-15 18:44 何太狼 阅读(572) 评论(0) 推荐(0)
摘要:extern与.h文件### extern `extern`是一个关键字。正常情况下,声明一个全局变量会自动定义它,并未它分配内存,但加上`extern`后不会定义,仅仅是声明。 ``` #include using namespace std; extern int a; int main() { cout using 阅读全文
posted @ 2022-05-08 20:39 何太狼 阅读(815) 评论(0) 推荐(0)