键盘获取输入

This commit is contained in:
flykhan 2023-06-15 16:43:42 +08:00
parent b1c38f25c4
commit ef7b0af039
2 changed files with 28 additions and 0 deletions

15
day4/d10.cpp Normal file
View File

@ -0,0 +1,15 @@
#include <iostream>
using namespace std;
int main()
{
char c = 'a'; // 1B
int m = 2; // 4B
// 小字节转大字节, 会自动转换
m += c; // 先将c转换为int,再相加
cout << "m = " << m << endl;
// 大字节转小字节,会丢失精度,需要强制类型转换
cout << "m to char is " << (char)m << endl;
return 0;
}

13
day4/d8.cpp Normal file
View File

@ -0,0 +1,13 @@
#include <iostream>
using namespace std;
int main()
{
int x1, y1, x2, y2;
cout << "请输入两个点坐标, 格式如 x1 y1 x2 y2" << endl;
cin >> x1 >> y1 >> x2 >> y2;
cout << "P1(" << x1 << "," << y1 << ")"
<< " P2(" << x2 << "," << y2 << ")" << endl;
return 0;
}