Compare commits
8 Commits
fae2ab8977
...
dev_xiaoxi
| Author | SHA1 | Date | |
|---|---|---|---|
| a84489c5de | |||
| 109ed8def8 | |||
| 6c23816ec2 | |||
| c03026824f | |||
| 181304d736 | |||
| e7270b2dad | |||
| b824e76a0c | |||
| 397c928058 |
18
c++常量类型的确定.cpp
Normal file
18
c++常量类型的确定.cpp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
//
|
||||||
|
// Created by violet on 2026/2/24.
|
||||||
|
//
|
||||||
|
#include "iostream"
|
||||||
|
#include "windows.h"
|
||||||
|
int main() {
|
||||||
|
SetConsoleOutputCP(CP_UTF8);
|
||||||
|
long long int i1 = 2212345678;
|
||||||
|
std::cout<<sizeof(i1)<<i1<<std::endl;
|
||||||
|
char a = 3;
|
||||||
|
char b = 32;
|
||||||
|
char c = 16;
|
||||||
|
char d = 17;
|
||||||
|
char e = '5';
|
||||||
|
char f = 126;
|
||||||
|
std::cout << f << std::endl;
|
||||||
|
std::cout <<c<<a<<b<<d<<e<<std::endl;
|
||||||
|
}
|
||||||
26
cin数据输入.cpp
Normal file
26
cin数据输入.cpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
//
|
||||||
|
// Created by viole on 2026/2/25.
|
||||||
|
//
|
||||||
|
#include <iostream>
|
||||||
|
#include "windows.h"
|
||||||
|
using namespace std;
|
||||||
|
int main() {
|
||||||
|
SetConsoleOutputCP(CP_UTF8);
|
||||||
|
string name;
|
||||||
|
double height;
|
||||||
|
int age;
|
||||||
|
cout << "请输入你的姓名:" <<endl;
|
||||||
|
cin >> name;
|
||||||
|
|
||||||
|
cout << "请输入你的身高(cm):" <<endl;
|
||||||
|
cin >> height;
|
||||||
|
|
||||||
|
cout << "请输入你的年龄:" <<endl;
|
||||||
|
cin >> age;
|
||||||
|
cout << "--------"<<endl;
|
||||||
|
cout << "信息输入完成,您的信息如下:"<<endl;
|
||||||
|
cout<<"姓名:"<<name<<endl;
|
||||||
|
cout<<"身高:"<<height<<endl;
|
||||||
|
cout<<"年龄:"<<age<<endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
21
if逻辑判断语句.cpp
Normal file
21
if逻辑判断语句.cpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
//
|
||||||
|
// Created by violet on 2026/3/3.
|
||||||
|
//
|
||||||
|
#include "iostream"
|
||||||
|
using namespace std;
|
||||||
|
int main() {
|
||||||
|
/*
|
||||||
|
* if(){}
|
||||||
|
*/
|
||||||
|
cout<<"今天发工资了"<<endl;
|
||||||
|
int money;
|
||||||
|
cout<<"请输入小明发的工资"<<endl;
|
||||||
|
cin>>money;
|
||||||
|
if (money>=10000) {
|
||||||
|
cout<<"小明去买电脑了"<<endl;
|
||||||
|
money -= 9900;
|
||||||
|
|
||||||
|
}
|
||||||
|
cout<<"小明工资还剩"<<money<<endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
25
三元运算符.cpp
Normal file
25
三元运算符.cpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// Created by violet on 2026/3/3.
|
||||||
|
//
|
||||||
|
#include "iostream"
|
||||||
|
using namespace std;
|
||||||
|
int main() {
|
||||||
|
int num1,num2;
|
||||||
|
|
||||||
|
// while (true){
|
||||||
|
//
|
||||||
|
// cout<<"请输入num1的值"<<endl;
|
||||||
|
// cin>>num1;
|
||||||
|
// cout<<"请输入num2的值"<<endl;
|
||||||
|
// cin>>num2;
|
||||||
|
// string value = num1>num2?"num1>num2":"num1<=num2";
|
||||||
|
// cout<<value<<endl;
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
cout<<"请输入小明第一次考试的成绩(0-100):"<<endl;
|
||||||
|
cin>>num1;
|
||||||
|
cout<<"请输入小明第二次考试的成绩(0-100):"<<endl;
|
||||||
|
cin>>num2;
|
||||||
|
cout<<"对小明的考试成绩进行判断,结果是:"<<(num1<num2?"买糖":"不买糖")<<endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
14
字符串.cpp
Normal file
14
字符串.cpp
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
//
|
||||||
|
// Created by violet on 2026/2/24.
|
||||||
|
//
|
||||||
|
#include <iostream>
|
||||||
|
namespace std {
|
||||||
|
int x =1;
|
||||||
|
}
|
||||||
|
int main() {
|
||||||
|
int a = 1;
|
||||||
|
auto b = std::x+1;
|
||||||
|
std::cout <<b<< std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
15
字符串拼接.cpp
Normal file
15
字符串拼接.cpp
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
//
|
||||||
|
// Created by viole on 2026/2/24.
|
||||||
|
//
|
||||||
|
#include "iostream"
|
||||||
|
using namespace std;
|
||||||
|
int main() {
|
||||||
|
string a = "1";
|
||||||
|
string b = "12";
|
||||||
|
string c = "13";
|
||||||
|
string d = "14";
|
||||||
|
int e = 12;
|
||||||
|
cout << a+b<<c+d<<a+to_string(e)<< endl;
|
||||||
|
bool b1 = true;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
22
实型数据类型.cpp
Normal file
22
实型数据类型.cpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
//
|
||||||
|
// Created by viole on 2026/2/24.
|
||||||
|
//
|
||||||
|
#include "iostream"
|
||||||
|
#include "windows.h"
|
||||||
|
using namespace std;
|
||||||
|
int main() {
|
||||||
|
SetConsoleOutputCP(CP_UTF8);
|
||||||
|
//float 单精度浮点数,4字节,6-7位的有效位数
|
||||||
|
float num1 = 1234567890;
|
||||||
|
float num2 = 1.234567890;
|
||||||
|
double num3 = 1234567890.1234567890;
|
||||||
|
long double num4 = 1234567890.1234567890;
|
||||||
|
cout<<fixed;
|
||||||
|
cout.width(20);
|
||||||
|
cout<<num1<<endl;
|
||||||
|
cout<<num2<<endl;
|
||||||
|
cout<<sizeof(num2)<<endl;
|
||||||
|
cout<<num3<<","<<sizeof(num3)<<endl;
|
||||||
|
cout<<num4<<","<<sizeof(num4)<<endl;
|
||||||
|
|
||||||
|
}
|
||||||
11
布尔数据类型.cpp
Normal file
11
布尔数据类型.cpp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
//
|
||||||
|
// Created by viole on 2026/2/25.
|
||||||
|
//
|
||||||
|
#include "iostream"
|
||||||
|
using namespace std;
|
||||||
|
int main() {
|
||||||
|
bool flag = 1;
|
||||||
|
bool flag2 = 0;
|
||||||
|
cout << flag << endl;
|
||||||
|
cout << flag2 << endl;
|
||||||
|
}
|
||||||
34
比较运算符.cpp
Normal file
34
比较运算符.cpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
//
|
||||||
|
// Created by violet on 2026/2/28.
|
||||||
|
//
|
||||||
|
#include "cstring"
|
||||||
|
|
||||||
|
#include "iostream"
|
||||||
|
using namespace std;
|
||||||
|
int main() {
|
||||||
|
//==相等 !=不等 >大于 <小于 <=小于等于>=大于等于
|
||||||
|
int num1 =3;
|
||||||
|
int num2 =4;
|
||||||
|
bool r1 = (num1!=num2);
|
||||||
|
cout<<r1<<endl;
|
||||||
|
//字符串要用strcmp比较,否则只能比较内存地址
|
||||||
|
char s1[]="hello";
|
||||||
|
char *s2 = "hello";
|
||||||
|
cout<<(strcmp(s1,s2))<<endl;
|
||||||
|
char s3[] = "a";
|
||||||
|
char *s4 = "b";
|
||||||
|
cout<<(strcmp(s4,s3))<<endl;
|
||||||
|
|
||||||
|
cout<<"字面量字符串"<<strcmp("a","b")<<endl;
|
||||||
|
//只要有一个c++风格的字符串,就可以用比较运算符来比较,比较他们的值而不是内存地址
|
||||||
|
string s5 = "a";//c++风格字符串
|
||||||
|
string s6 = "a";
|
||||||
|
cout<<(s5== s6)<<endl;
|
||||||
|
cout<<(1==1 && 2==2)<<endl;
|
||||||
|
cout<<(1==2 && 2==2)<<endl;
|
||||||
|
cout<<(1==2 || 2==3)<<endl;
|
||||||
|
cout<<(1==2 || 2==2)<<endl;
|
||||||
|
bool s123 = 100;
|
||||||
|
cout<<(s123)<<endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
19
算数运算符.cpp
Normal file
19
算数运算符.cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
//
|
||||||
|
// Created by violet on 2026/2/28.
|
||||||
|
//
|
||||||
|
#include "iostream"
|
||||||
|
using namespace std;
|
||||||
|
int main() {
|
||||||
|
//单目(一个操作数)运算符
|
||||||
|
int num1 = +10;
|
||||||
|
int num2 = -10;
|
||||||
|
cout <<num1<<","<<num2<<endl;
|
||||||
|
//双目(有两个操作数)操作符
|
||||||
|
int num3 = 5+5;
|
||||||
|
int num4 = 5-3;
|
||||||
|
int num5 = 5*5;
|
||||||
|
int num6 = 10/3;
|
||||||
|
int num7 = 10%3;
|
||||||
|
cout<<num3<<","<<num4<<","<<num5<<","<<num6<<","<<num7<<endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
23
赋值运算符.cpp
Normal file
23
赋值运算符.cpp
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
//
|
||||||
|
// Created by violet on 2026/2/28.
|
||||||
|
//
|
||||||
|
#include "iostream"
|
||||||
|
using namespace std;
|
||||||
|
int main() {
|
||||||
|
int num =2,num1,num2,num3,num4,num5;
|
||||||
|
num +=3;cout<<num<<endl;
|
||||||
|
bool a = true;
|
||||||
|
cout<<a<<endl;
|
||||||
|
|
||||||
|
|
||||||
|
num -=2,cout<<num<<endl,
|
||||||
|
num *=2,cout<<num<<endl,
|
||||||
|
num /=3,cout<<num<<endl,num %=2,cout<<num<<endl;
|
||||||
|
int money = 50;
|
||||||
|
money-=5;
|
||||||
|
money+=10;
|
||||||
|
money-=2;
|
||||||
|
money*=2;
|
||||||
|
cout<<money<<endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
13
转义字符.cpp
Normal file
13
转义字符.cpp
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
//
|
||||||
|
// Created by violet on 2026/2/24.
|
||||||
|
//
|
||||||
|
//转义字符:将普通的字符使用\作为开头,将其含义进行转换,对照得到ascii表的控制字符的功能
|
||||||
|
//\n \t \\ \'\"
|
||||||
|
#include "iostream"
|
||||||
|
#include "windows.h"
|
||||||
|
int main() {
|
||||||
|
SetConsoleOutputCP(CP_UTF8);
|
||||||
|
std::cout<<"aa\tbbbb"<< std::endl;
|
||||||
|
std::cout<<"aa\t\tbbbb"<<std::endl;
|
||||||
|
std::cout<<"aa\taabbbbaabbbb"<<std::endl;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user