![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c++
陈冲一
这个作者很懒,什么都没留下…
展开
-
static记录
static静态变量,和普通变量的区别就是生命周期与作用域不同。主要在一下:1.静态成员变量属于整个类所有2.生命期不依赖于任何对象,为程序的生命周期3.可以通过类名直接访问公有静态成员变量4.所有对象共享类的静态成员变量5.可以通过对象名访问公有静态成员变量6.静态成员变量需要在类外单独分配空间7.属于全局数据区`#include <iostream>#include <string> using namespace std; class ccy{p原创 2021-06-07 19:39:40 · 59 阅读 · 0 评论 -
c++ 从txt文件读取内容,读取某一行数据
#include <iostream>#include <fstream>#include <string>using namespace std;struct game{ int num; int year; float arr[3];};struct gj{ int a; game dz;};int count_lines(char *filename) { int n = 0; ifstream Re原创 2021-05-31 20:45:11 · 2729 阅读 · 0 评论 -
c++ 实现读取文件,并把嵌套结构体保存到txt文件,读到符合满足行数时,删除,重新写入
#include <iostream>#include <fstream>#include <string>using namespace std;struct game{ int num; int year; float arr[3];};struct gj{ int a; game dz;};int count_lines(char *filename);int main(){ char filename[原创 2021-05-31 15:45:42 · 759 阅读 · 1 评论 -
stack栈中存入结构体对象
为了功能,方便数据回读,需要用到栈,倒序读数据#include <stack>#include <iostream>#include <algorithm>#include <vector>using namespace std;int main(){ struct a { int q; float w; int e; }; // struct b // {原创 2021-05-24 16:59:17 · 1596 阅读 · 0 评论 -
enum枚举
因为需要两个芯片通信,其中传递的id是枚举类型,所以学习下举例enum color { red, yellow, blue};如何用#include<stdio.h>enum color { red, yellow, blue};void f(enum color x) { printf("%d\n", x);}int main(void) { // 变量 t 的类型是 enum color enum color t =原创 2021-05-21 08:48:16 · 77 阅读 · 0 评论 -
类-继承
基类#ifndef TABTENNO_H_#define TABTENNO_H_class TableTennisPlayer{priveate: enum {LIM = 20}; char firstname[LIM]; bool hasTable;public: TableTennisPlayer(const char * fn = "none, const char * ln = "none", bool ht = false); void Na原创 2021-05-11 20:16:34 · 66 阅读 · 0 评论 -
const
参考https://blog.csdn.net/weixin_39345003/article/details/81276968?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-2.vipsorttest&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefaul原创 2021-05-10 16:28:55 · 60 阅读 · 0 评论 -
c++ 对象和类
内容包括构造函数和析构函数类类声明:以数据成员的方式描述了数据部分,以成员函数(方法)的方式描述公有接口。类方法定义:描述如何实现类成员函数。定义位于类声明中的函数都将自动称为内联函数。c++的目标是使得使用类与使用基本的内置类型尽可能相同。要创建类对象,可以声明类变量,也可以使用new为类对象分配存储空间,可以将对象作为函数的参数和返回值,也可以将一个对象赋给另一个。#include <iostream>#include <cstring>class Stoc原创 2021-05-10 12:38:39 · 66 阅读 · 0 评论 -
namespace命名空间
笔记命名空间变量、函数和类大量存在,为了避免冲突,使用命名空间。比如两个地方的张三不是同一个人。1.定义访问 N::anamespace N{ int a; int b; int add(int a, int b) { return a+ b; } }命名空间的嵌套namespace N1{ int a;//定义变量 int add(int a,int b)//定义函数 { return a+b; } nam原创 2021-05-08 14:43:14 · 71 阅读 · 0 评论 -
c++ 函数
需要做的?1.提供函数定义2.提供函数原型3.调用函数定义函数函数分成两类:有无返回值没有返回值ex:void fun(param){ statement(s); return;}有返回值int max(int a, int b) { if (a > b) { return a; } else { return b; }}函数原型为什么需要函数函数原型?原型描述了函数到编译器的接口。如何表述?函原创 2021-05-08 12:09:22 · 101 阅读 · 0 评论