本文围绕 C++ 的Syntax, Data Structures,
Algorithms以及STL和相关高频应用进行集中攻克,既能提升在 C++ 面试前的准备效率,也能提前把握实际工作中的 C++ 要点。
C++
STL(标准模板库)是一套C++模板类,提供通用的模板类和函数容器-Containers:用于管理某一类对象的集合算法-Algorithms:作用于容器,提供了执行各种操作的方式迭代器-Iterators:用于遍历对象集合的元素向量 Vector:能够存放任意类型的动态数组1.顺序序列:元素按线性顺序排序;可通过元素在序列中的位置访问对应的元素2.动态数组:对序列中任意元素进行快速直接访问;提供在序列末尾相对快速地添加/删除元素C++中两种输入输出方式:cin、cout;效率低;因为输出时将内容先放入缓冲区再输出使用ios::sync_with_stdio(false);使内容不在缓存直接输出
std::vector<int> v1(3); // 1. Create a vector v1 with 3 elements of default value 0 std::vector<int> v2(5, 2); // 2. Create a vector v2 with 5 elements of value 2 std::vector<int> v3(3, 1, v2.get_allocator()); // 3. Create a vector v3 with 3 elements of value 1 and with the allocator of vector v2 std::vector<int> v4(v2); // 4. Create a copy, vector v4, of vector v2 std::vector<int> v5(v4.begin() + 1, v4.begin() + 3); // 5. Create a vector v5 by copying the range v4[_First, _Last)
string a; //默认"" a += 'd'; a += "ansjcknkj"; a.back(); //返回最后一个字符 string b = a.substr(1,5); //从位置1向后截取5个字符的子字符串 a.pop_back(); //去掉最后一个字符 string c = to_string(1); //整数to string c = to_string(1.98); //float to string int d = stoi("890"); //string to int