摘要:
9.50 编写程序处理一个vector,其元素都表示整数型。计算vector中所有元素之和。修改程序,使之计算表示浮点值的string之和。程序如下:#include#include#includeusing namespace std;int main(){ vector str={"1",... 阅读全文
摘要:
9.47 编写程序,首先查找string"ab2c3d7R4E6"中的每个数字字符,然后查找其中每个字母字符。编写两个版本的程序,第一个要使用find_first_of,第二个要使用find_first_not_of。程序如下:#include#includeusing namespace std;... 阅读全文
摘要:
9.43 编写一个函数,接受三个string参数s、oldVal和newVal。使用迭代器及insert和erase函数将s中所有oldval替换为newVal。测试程序,用它替换通用的简写形式,如,将“tho”替换为“though”,将“thru”替换为“through”。程序如下:#includ... 阅读全文
摘要:
9.28 编写函数,接受一个forward_list和两个string共三个参数。函数应在链表中查找第一个string,并将第二个string插入到紧接着第一个string之后的位置。若第一个string未在链表中,则将第二个string插入到链表末尾。#include#include#includ... 阅读全文
摘要:
#include#includeusing namespace std;int main(){ forward_list flst={0,1,2,3,4,5,6,7,8,9}; auto prev=flst.before_begin(); auto curr=flst.begin(... 阅读全文