
c++
循环是人递归是神
北京邮电大学
展开
-
C++ assert与try, catch
assert:根据判断条件,如果不满足则抛出异常,但仅限于Debug模式try, catch:Debug模式和Release模式均可。try, catch详细用法:https://blog.youkuaiyun.com/qq_40191710/article/details/81063878 https://www.jb51.net/article/80913.htm更新一下上面链接的代码 :-)C++的异常处理的基本思想大致可以概括为传统...原创 2020-10-27 21:08:02 · 2267 阅读 · 0 评论 -
选择排序,冒泡排序,插入排序,归并排序,快速排序模板
template<typename T>void selection_sort(vector<T>& a) { for (int i = 0; i < a.size() - 1; i++) { int min = i; for (int j = i + 1; j < a.size(); j++) if (a[j] < a[min]) min = j; swap(a[i], a[min]); }}template<.原创 2020-08-24 19:47:31 · 146 阅读 · 0 评论 -
C++ 虚函数的两个例子
虚函数是动态联编的eg1:class A{public: virtual void foo() { cout << "A::foo() is called" << endl; }};class B :public A{public: void foo() { cout << "B::foo() is called" << endl; }};int main(void){ A *a = new B(); a-.原创 2020-08-12 21:17:00 · 238 阅读 · 0 评论 -
c++ vector的erase用法
vector<int> a = { 1,2,3}; vector<int>::iterator it = a.begin(); a.erase(it,it+2);//擦除a从it开始的两个元素,结果a = {3} vector<int> a = { 1,2,3}; vector<int>::iterator it = a.begi...原创 2020-02-21 05:28:59 · 2396 阅读 · 0 评论 -
动态一维和二维数组
//一维数组int *test1;test1 = new int[5]; //二维数组int **test2;test2 = new int *[row];int row = 4, col = 5;for (int i = 0; i < row; i++){ test2[i] = new int[col];}原创 2019-11-10 14:10:58 · 115 阅读 · 0 评论 -
using namespace和using
namespace Jill{ double bucket(double n) { return 0; }; double fetch; int pal; struct Hill {};}char fetch;int main(){ using Jill::fetch; double fetch //error!重定义; std::cin >> fetch;/...原创 2019-11-09 22:33:39 · 142 阅读 · 0 评论 -
c++读文件
下面代码读文件的时候,注意会读回车。#include<iostream>#include<algorithm>#include <direct.h>#include<fstream>using namespace std;int a[1005];int b[1005];int main(){ /*char buf1[...原创 2019-11-07 14:20:08 · 142 阅读 · 0 评论 -
c++ vector作为形参,设置默认值
#include<iostream>#include<set>#include<string>#include<sstream>#include<vector>#include<algorithm>#include<string>using namespace std;;void threeSum...原创 2019-10-18 23:11:31 · 6754 阅读 · 2 评论 -
Eigen HouseholderQR分解
#include <vector>#include <algorithm>#include <iostream>#include <Eigen/Dense>using namespace std;using namespace Eigen;int main(){ Matrix3d A; A << 1, 1, 1,...原创 2019-09-26 11:35:07 · 4084 阅读 · 0 评论 -
c++读写文件
#include<fstream>#include<iostream>using namespace std;int main(){ // *************************写txt文件******************************* //ofstream OutFile; //实例一个写文件...转载 2019-09-26 09:55:12 · 221 阅读 · 0 评论 -
c++ 字符串分割的实现
#include <stdio.h>#include <stdlib.h>#include <string.h>#include<iostream>using namespace std;int main(){ const char *s; char str[] = "C:\\Users\\Administrator.DESKTOP...原创 2019-04-27 16:52:29 · 313 阅读 · 0 评论 -
关于char的一些细节
当char c = 0执行时,0是作为int类型赋给c,所以c对应的应该是ASCII值为0符号(空格),当然c==0是成立的,c=='0'不成立。#include <iostream>using namespace std;int main(){ char c = 0; if (c == 0) cout << "c==0...原创 2019-04-13 01:07:39 · 177 阅读 · 0 评论 -
c++引用传递
将int &p1 = x, &p2 = y;fun1(p1, p2);替换为fun1(x,y);输出结果一样,表明调用含引用传递的函数时,参数前的 & 可以省略#include <iostream>using namespace std;int main(){ void fun(int x, int y); void fun1(i...原创 2019-04-12 23:08:49 · 843 阅读 · 0 评论