
C++ 语法
死咸鱼的成长之路
这个作者很懒,什么都没留下…
展开
-
编译的4个过程
gcc -E main.c -o main.i 生成.i文件gcc -S main.i –o main.s 生成.s文件gcc –c main.s –o main.o 生成.o文件gcc main.s –o main 链接,生成.exe(可执行)文件main 运行aa.h头文件int add(int a,int b);aa.c源文件#i...原创 2019-12-28 13:39:39 · 469 阅读 · 0 评论 -
gets fgets 与缓冲区的概念
#include <stdio.h>#include <iostream>#include <string.h>#define N 5int main(){ char s1[N]; char s2[N]; char s3[N]; //只能从缓冲区读取N-1个字符 如果小于N-1 读取到 并且 保留回车 fgets(s1, N,...原创 2018-11-30 19:11:46 · 1487 阅读 · 1 评论 -
C++11 lambda表达式
[capture](parameters) mutable ->return-type{statement} 捕获列表与函数比必须存在 -> 可省略 如果无参数 参数列表连同括号可省略#include "pch.h"#include <iostream>#include <vector>#include <algorithm>...原创 2018-11-29 12:02:39 · 303 阅读 · 0 评论 -
向算法传递函数 ---- sort,stable_sort,unique
// 向算法传递函数(Primer_P344).cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。//#include "pch.h"#include <iostream>#include <string>#include <vector>#include <functional>#include <al原创 2018-11-22 21:47:09 · 299 阅读 · 0 评论 -
泛型算法
// 泛型算法.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。//#include "pch.h"#include <iostream>#include <vector>#include <iterator>#include <algorithm>#include <numeric>#原创 2018-11-23 17:39:44 · 149 阅读 · 0 评论 -
.h与.cpp在连接时重复定义问题
一、多文件中函数的声明与定义A.h#pragma once#include <iostream>void fun() { std::cout << "我是fun()函数" << std::endl;}a.cpp#include "pch.h"#include "A.h"int main(){ return 0;}..原创 2018-11-19 12:04:21 · 2389 阅读 · 0 评论 -
运算符重载------()重载
#include <iostream>using namespace std;class Distance{private: int feet; // 0 到无穷 int inches; // 0 到 12public: // 所需的构造函数 Distance() { feet = 0; inches = 0; ...原创 2018-11-20 21:34:10 · 240 阅读 · 0 评论 -
运算符重载----关系运算符重载
#include <iostream>using namespace std;class A {private: int x;public: A(int y) { x = y; } bool operator < (const A& a) { if (x < a.x) return true; else return fa...原创 2018-11-20 21:28:15 · 674 阅读 · 0 评论 -
条件编译
<标识>在理论上来说可以是自由命名的,但每个头文件的这个“标识”都应该是唯一的。标识的命名规则一般是头文件名全大写,前后加下划线,并把文件名中的“.”也变成下划线,如:stdio.h#ifndef _STDIO_H_#define _STDIO_H_ #define 定义一个预处理宏#undef 取消宏的定义#if ...原创 2018-11-04 16:22:49 · 714 阅读 · 0 评论 -
this指针的理解
#include "stdafx.h"#include "pch.h"#include <iostream>#include <cstring>#include <cstdlib>using namespace std;#pragma warning(disable:4996)class CDemo{public: CDemo( ch...原创 2018-10-11 12:37:28 · 2470 阅读 · 0 评论 -
#pragma warning(disable:4996)
测试一段程序,里面有strcpy这个函数 但是在VS编译器中会报警告 error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online h...原创 2018-10-11 11:02:20 · 15411 阅读 · 0 评论 -
多态性
虚函数#include "stdafx.h"#include <iostream>#include <string>using namespace std;//动态绑定:当我们使用基类的引用或指针调用一个虚成员函数时会执行动态绑定。//我们知道运行时才能知道到底调用了哪个版本的函数。class A {public: virtual void get...原创 2018-04-25 18:44:52 · 133 阅读 · 0 评论 -
cout格式化输出
1.不知域宽前补0#include <iostream>#include <string>#include <vector>#include <iomanip>using namespace std;#define _for(i,a,b) for( int i = (a) ; i <(b) ; i++)#define MAX 25...原创 2018-04-11 20:35:31 · 146 阅读 · 0 评论 -
typename和模板的使用
#include<iostream>#include <queue>#include <iterator>using namespace std;class Myarray{public: typedef double LEN; LEN Getlength(){ return 1.23012345; } }; //typename的...原创 2018-03-13 17:09:37 · 572 阅读 · 0 评论