support bazel complie this project and format code.

This commit is contained in:
zhangxing
2023-03-30 00:15:11 +08:00
committed by light-city
parent 1f86192576
commit 7529ae3a55
636 changed files with 10025 additions and 9387 deletions

View File

@@ -0,0 +1,18 @@
# please run `bazel run //practical_exercises/10_day_practice/day10/file/input:getline`
# please run `bazel run //practical_exercises/10_day_practice/day10/file/input:get2`
# please run `bazel run //practical_exercises/10_day_practice/day10/file/input:get`
load("@rules_cc//cc:defs.bzl", "cc_binary")
cc_binary(
name = "getline",
srcs = ["getline.cpp"],
)
cc_binary(
name = "get2",
srcs = ["get2.cpp"],
)
cc_binary(
name = "get",
srcs = ["get.cpp"],
)

View File

@@ -0,0 +1,20 @@
//【例12-2】 用函数get和getline读取数据。
#include <iostream>
using namespace std;
int main() {
char a, b, c, d;
cin.get(a);
cin.get(b);
c = cin.get();
d = cin.get();
cout << int(a) << ',' << int(b) << ',' << int(c) << ',' << int(d) << endl;
return 0;
}
/*
用法a = cin.get() ?或者 ?cin.get(a)
结束条件:输入字符足够后回车
说明这个是单字符的输入用途是输入一个字符把它的ASCALL码存入到a中
处理方法与cin不同cin.get()在缓冲区遇到[enter][space][tab]不会作为舍弃,而是继续留在缓冲区中
*/

View File

@@ -0,0 +1,44 @@
//【例12-2】 用函数get和getline读取数据。
#include <iostream>
using namespace std;
// cin.get(arrayname,size) 把字符输入到arrayname中长度不超过size
int main() {
// get()两个参数
// 1.输入串长<size输入串长>arraylength会自动扩张arrayname大小使能保存所有数据
// char a[10];
// cin.get(a,20);
// cout<<a<<endl;
// cout<<sizeof(a)<<endl;
// 2.输入串长<size输入串长<arraylength把串全部输入后面补\0
// char b[10];
// cin.get(b,20);
// cout<<b<<endl;//12345此时数组内数据为12345'\0
// cout<<sizeof(b)<<endl;
// 3.输入串长>size先截取size个字符若还是大于arraylength则自动扩张arrayname大小使能保存所有数据
// char c[5];
// cin.get(c,10);
// cout<<c<<endl;
// cout<<sizeof(c)<<endl;
// 4.输入串长>size先截取size个字符若小于arraylength则把截取串放入数组中最后补充\0
// char d[10];
// cin.get(d,5);
// cout<<d<<endl;
// cout<<sizeof(d)<<endl;
// get()三个参数
/*
用法cin.get(arrayname,size,s)
?把数据输入到arrayname字符数组中当到达长度size时结束或者遇到字符s时结束
注释a必须是字符数组即char
a[]l类型不可为string类型size为最大的输入长度s为控制遇到s则当前输入结束缓存区里的s不会被舍弃
*/
int i;
char e[10];
cin.get(e, 8, ',');
cout << e;
return 0;
}

View File

@@ -0,0 +1,38 @@
#include <iostream>
using namespace std;
/*
1cin.getline(arrayname,size)与cin.get(arrayname,size)的区别
cin.get(arrayname,size)当遇到[enter]时会结束目前输入,他不会删除缓冲区中的[enter]
cin.getline(arrayname,size)当遇到[enter]时会结束当前输入,但是会删除缓冲区中的[enter]
*/
int main() {
/*
char a[10];
char b;
cin.get(a,10);
cin.get(b);
cout<<a<<endl<<int(b);//输入12345[enter] 输出12345 【换行】 10*/
/*char c[10];
char d;
cin.getline(c,10);
cin.get(d);
cout<<c<<endl<<int(d);//输入12345[enter]a[enter] 输出12345【换行】97*/
// cin.getline(arrayname,size,s)与cin.gei(arrayname,size,s)的区别
/*
cin.getline(arrayname,size,s)当遇到s时会结束输入并把s从缓冲区中删除
cin.getarrayname,size,s当遇到s时会结束输入但不会删除缓冲区中的s
*/
/*
char e[10];
char f;
cin.get(e,10,',');
cin.get(f);
cout<<e<<endl<<f;//输入12345,[enter]
输出12345【换行】说明cin,get不会删除缓冲区的*/
char e1[10];
char f1;
cin.getline(e1, 10, ',');
cin.get(f1);
cout << e1 << endl << f1; //输入asd,wqe 输出asd【换行】w
}