李迟2021年7月知识总结

本文为 2021 年 7 月知识总结。

编码总结

C / C++

读取文件,在得到一行字符串中查找中文:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int readIFile2Map(const char* filename)
{
truestring str;
ifstream ifs1(filename);

if(!ifs1.is_open()){
printf("open %s failed\n", filename);
return -1;
}

trueint flag = 0;
while(getline(ifs1, str))
{
// printf("str: [%s]\n", str.c_str());
truetrue// 直接查中文,不知是否一直可行?
truetrueif ((int)str.find("新增列表,") > 0) flag = 1;
truetrueif ((int)str.find("差异列表,") > 0) flag = 2;
}
}

注:当读取的文件格式为UTF8时,C++源码文件亦要UTF8。原则上应保持编码格式一致。细节未深入。

二维数组引用传递:

1
2
3
4
5
6
7
8
test_new.cpp:508:109: 错误:‘diffTypeCount’声明为引用的数组
std::map<std::string, int> mIntervalDiff, int& diffTypeCount[4], bool needCheck)

原声明:
void calcDiffSPath(std::map<std::fstd::map<std::string, int> mIntervalDiff, int& diffTypeCount[4], bool needCheck)
现改为:
void calcDiffSPath(std::map<std::fstd::map<std::string, int> mIntervalDiff, int(& diffTypeCount)[4], bool needCheck)
问题解决。

golang

切片删除示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
seq := []string{"a", "b", "c", "d", "e"}  
// 删除第2个索引,即c
index := 2
seq = append(seq[:index], seq[index+1:]...)

// 删除前面4个,即索引0~索引3,a~d
index := 3
seq = append(seq[:0], seq[index+1:]...)

// 删除最后一个
seq = append(seq[:len(seq)-1])

结构体切片清空:
fooInfo = []UserInfo{}

编码其它

一般知识

研发思考

部门要过CMMI,这个月请老师来培训了CMMI5。后面自己实操,发现除了文档就是文档,代码倒是次要的了。

本月学习及计划

其它点滴

买房提上日程了,业余写代码时间减少了,陪小孩的时间也少了。