C++
好喜欢吃红柚子
行到水穷处,坐看云起时
展开
-
C++ STL(蓝桥杯应急)
vector///vectorvector<int> v; vector<int> ::iterator i; for(int i=0;i<10;i++) v.push_back(i); for(i=v.begin();i!=v.end();i++) printf("%d ",*i); printf("\n"); i=v.begin()+5; v.insert(i,12); v.er原创 2022-04-08 23:10:59 · 837 阅读 · 0 评论 -
使用vector赋值语句的注意事项
使用vector<string> v语句声明时,不能使用v[1]="hhh"这种赋值方式进行赋值,因为使用该语句声明时,该数组还不存在!!!原创 2021-12-29 00:57:11 · 406 阅读 · 0 评论 -
数据结构实训记录
1. vector和iterator迭代器使用v.begin()和v.end()访问vector的头和尾,*i表示迭代器访问的元素#include <iostream>#include<vector>using namespace std;int main(){ vector<int> v; for(int n=0;n<5;n++){ v.push_back(n); } vector<...原创 2021-12-21 11:24:14 · 294 阅读 · 0 评论 -
STL工具之vector的使用
vector的使用方法:1)vector<int>a定义一个int类型的vector一维数组。(2)vector<int>a(10)定义一个int类型的长度为十的vector一维数组。(3)vector<int>a(10)(1)定义一个int类型的长度为十初值为一的vector一维数组。(4)vector<vector<int>>a定义一个int类型的vector二维数组,要注意的是,在里面的vecotr<...原创 2021-03-25 21:45:05 · 365 阅读 · 0 评论 -
第五周:Random随机数的练习
一、 初步了解1. setw(int n)头文件:#include<iomanip>占位函数,处理输出间隔的问题,占n个位,不足的用空格补充2. rand( )头文件:#include<cstdlib>rand( ) %n:产生【0,n-1】 的随机数;rand( ) %n+1:产生【1,n】的随机数;程序1:#include <iostream>#include<iomanip> //cintains the..原创 2021-03-31 10:21:45 · 441 阅读 · 0 评论 -
zork项目
1. vector的使用push_back( 参数 ) :在vector最后新添加一个元素command.h#ifndef COMMAND_H_#define COMMAND_H_#include <string>using namespace std;class Command {private: string commandWord; string secondWord;public: Command(string firstWord, str.原创 2021-03-28 13:27:52 · 629 阅读 · 2 评论 -
类练习1 rectangle类
题目:建rectangle类,有长和宽,自定义构造方法,自定义求周长函数目录一、qt入门使用注意:二、代码实现1.Rectangle.h文件2.Rectangle.cpp文件3.main.cpp文件一、qt入门使用注意:一定要新建项目,没有项目无法编译源文件 新建的.cpp 和.h文件都要加入到建好的同一个项目中才可以运行! qt里类.cpp文件自己建好时会加一个类名::类名(),这个必须去掉才没有错误! 二、代码实现1...原创 2021-03-16 22:18:32 · 545 阅读 · 0 评论 -
c++自学整理3 选择结构
目录4.1.2 三目运算符4.1.3 switch语句while循环练习案例:==猜数字==4.2.2 do...while循环语句4.2.4 嵌套循环练习案例:乘法口诀表4.3.3 goto语句4.1.2 三目运算符作用: 通过三目运算符实现简单的判断语法:表达式1 ? 表达式2 :表达式3解释:如果表达式1的值为真,执行表达式2,并返回表达式2的结果;如果表达式1的值为假,执行表达式3,并返回表达式3的结果。#includ...原创 2021-03-06 15:50:20 · 194 阅读 · 0 评论 -
事件驱动编程上课记录1
课上练习代码#include <iostream>using namespace std;int main(){ int x=0,y=0,z=0,result; cout<< "Please enter 3 integers" << endl; cin >> x>>y>>z; result = x*y*z; cout << "The produce is" <<原创 2021-03-06 13:50:10 · 70 阅读 · 0 评论 -
QT编译错误:Error while building / destroying project xxx
QT原创 2021-03-06 12:59:05 · 109 阅读 · 0 评论 -
c++ 整理2
2.7 布尔类型bool flag = true;#include <iostream>using namespace std;int main(){ bool flag = true; cout << flag << endl; cout << sizeof(flag) << endl; return 0;}11 (bool类型占一个字节)2.8 数据输入...原创 2021-03-01 22:25:52 · 1843 阅读 · 0 评论 -
C++自学整理1
基础1. 头文件#include <iostream>using namespace std;2. 输入cout << "Hello word!" << endl3. 常量 : const int n = 3; (n不可修改)4. sizeof 关键字cout << "int型数据的长度是:" << sizeof(int) << endl5. 转义字符\t 水平制表...原创 2021-02-21 19:01:28 · 82 阅读 · 0 评论