C++ 工具¶
输入输出工具¶
cin¶
getline(buf, num)丢弃换行符get(buf, num)换行符留在输入队列中get()读取一个字符clear()fail(), eof()检测到EOF后,cin的failbit和eofbit都置1;
get()(不是getline())读取空行后设置失效位(failbit),需要使用cin.clear()恢复。
get(), getline()输入行的字符比指定容量多时,将设置失效位
cin.get(name, ArSize).get();
cout, wcout¶
put()setf(ios_base::fixed, ios_base::floatfield);
文件IO fstream¶
ofstream fout = open(name);
fout.close();
输出格式¶
格式备份与恢复
fmtflags fmt = cout.flags();
cout.flags(fmt);
setioflags(ios_base::fixed | ios::showpoint)precision(...)setprecision(2)
进阶数据结构¶
std::vector, std::array¶
中括号语法不检查下标越界,成员函数at()检查下标越界
std::map, std::unordered_map¶
find()count(),contains()