第一周

第一题 身份证的读取

用到的知识

ifstream 文件流

//1. 打开文件
ifstream inFile;
inFile.open(sFilePath, ios::in); //in 读 out 写 binary 二进制读等等
if(!inFile){
		return -1;
	}else{
		cout << "success!" << endl;
	}

查找文件的字节大小

 	fstream inFile;
	inFile.open(m_sFilePath, ios::in);
	inFile.seekg(0, ios::end);     //指向末尾位  ios::end
	m_nFileSize = (long)inFile.tellp();  //读取当前所指位置的pos
	inFile.seekg(0, ios::beg);     //归位 指向0   ios::beg
	inFile.close();

lambda函数

auto GetMonthDay = [](int year, int month) {
		int arrayDay[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
		if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))) {
			return 29;
		}
		else {
			return arrayDay[month];
		}
	};

字符串操作

auto comPare_1 = [](const string &s1, const string &s2){
		return stoi(s1.substr(6, 8)) <= stoi(s2.substr(6, 8));
};

**s1.substr(6, 8)   //截取字符串  从pos = 6 处 向后截取8个字符
stoi(s1.substr(6, 8))  //字符串转数字**