摘要: 题目:编写函数,返回一个动态分配的int的vector。将此vector传递给另一个函数,这个函数读取标准输入,将读入的值保存在vector元素中。再将vector传递给另外一个函数,打印读入的值。记得在恰当的时刻delete vector。 阅读全文
posted @ 2016-09-16 10:24 KennyRom 阅读(246) 评论(0) 推荐(0) 编辑
摘要: to_string(val); //数值val的string表示 stoi (s, p, b); stol (s, p, b); stoul (s, p, b); stoll (s, p, b); stoull (s, p, b); stod (s, p); //b表示转换的基数, p是size_t指针, 用于保存s中第一个非数值符下标,默认为0 阅读全文
posted @ 2016-09-15 09:19 KennyRom 阅读(188) 评论(0) 推荐(0) 编辑
摘要: 题目:如果一个字母延伸到中线之上,如d或f,则称其有上出头部分(ascender)。如果一个字母延伸到中线之下,如p或g,则称其有下出头部分(descender)。编写程序,读入一个单词文件,输出最长的既不包含上出头部分,也不包含下出头部分的单词。 阅读全文
posted @ 2016-09-15 09:11 KennyRom 阅读(256) 评论(0) 推荐(0) 编辑
摘要: 题目要求:编写一个函数,接受三个string参数s,oldVal和newVal。使用迭代器及insert和erase函数将s中所有oldVal替换为newVal。测试你的程序,用它替换通用的简写形式,如,将"tho"替换为"though",将"thru"替换为"though"。 阅读全文
posted @ 2016-09-15 08:39 KennyRom 阅读(292) 评论(0) 推荐(0) 编辑
摘要: #include #include #include using namespace std; int main() { vectorc = { '1', '2', '3' }; string s(c.begin(),c.end()); cout << s << endl; return 0; } 阅读全文
posted @ 2016-09-14 15:34 KennyRom 阅读(6862) 评论(0) 推荐(0) 编辑
摘要: shrink_to_fit 只适用于vector, string, deque capacity 只适用于vector, string c.shrink_to_fit(); 将capacity减少为size c.capacity(); 不重新分配,c可以容纳多少元素 c.reserve(n); 分配 阅读全文
posted @ 2016-09-14 13:58 KennyRom 阅读(159) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std; int main() { forward_list vi = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; auto it1 = vi.before_begin(); auto it2 = vi.begin(); while (it2 != vi.end()) ... 阅读全文
posted @ 2016-09-14 10:07 KennyRom 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 一、向容器添加元素时 ①vector & string if 储存空间重新分配 迭代器、引用&指针都失效 if 没有重新分配 插入位置之前都有效 ②deque 插入到除首尾外都会失效 if 首尾添加,迭代器失效,其他不失效 ③list & forward_list 都有效 二、从容器中删除元素 ①l 阅读全文
posted @ 2016-09-14 09:18 KennyRom 阅读(162) 评论(0) 推荐(0) 编辑
摘要: class c { public: returnType functionName (parameter list) const; //这个函数不会修改类成员 const returnType functionName (parameter list); //返回常量 private: ........... }; ... 阅读全文
posted @ 2016-09-12 22:54 KennyRom 阅读(536) 评论(0) 推荐(0) 编辑
摘要: Type(*function(parameter_list)) [dimension] or 使用类型别名 typedef int arr[10]; or using arr=int[10] 阅读全文
posted @ 2016-09-12 19:50 KennyRom 阅读(212) 评论(0) 推荐(0) 编辑