C++ Primer 第5版--练习9.47
来源:互联网 发布:thinkphp3.2 商城源码 编辑:程序博客网 时间:2024/06/03 16:07
练习 9.47:编写程序,首先查找string "ab2c3d7R4E6" 中的每个数字字符,然后查找其中每个字母字符。编写两个版本的程序,第一个要使用 find_first_of,第二个要使用 find_first_not_of。
使用find_first_of的版本如下:
#include <iostream>#include <string>using std::cout;using std::string;int main(){ string s("ab2c3d7R4E6"); string numbers("0123456789"); string alphabet("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); cout << "string \"ab2c3d7R4E6\"中的数字字符是:"; for (string::size_type pos = 0; (pos = s.find_first_of(numbers, pos)) != string::npos; ++pos) cout << s[pos]; cout << "\nstring \"ab2c3d7R4E6\"中的字母字符是:"; for (string::size_type pos = 0; (pos = s.find_first_of(alphabet, pos)) != string::npos; ++pos) cout << s[pos]; return 0;}
使用find_first_not_of的版本如下:
#include <iostream>#include <string>using std::cout;using std::string;int main(){ string s("ab2c3d7R4E6"); string numbers("0123456789"); string alphabet("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); cout << "string \"ab2c3d7R4E6\"中的数字字符是:"; for (string::size_type pos = 0; (pos = s.find_first_not_of(alphabet, pos)) != string::npos; ++pos) cout << s[pos]; cout << "\nstring \"ab2c3d7R4E6\"中的字母字符是:"; for (string::size_type pos = 0; (pos = s.find_first_not_of(numbers, pos)) != string::npos; ++pos) cout << s[pos]; return 0;}
0 0
- C++primer第5版课后练习习题答案9.47
- C++ Primer 第5版--练习9.47
- C++primer第5版课后练习习题答案 9.4
- C++primer第5版课后练习习题答案9.5
- C++primer第5版课后练习习题答案9.16
- C++primer第5版课后练习习题答案 9.20
- C++primer第5版课后练习习题答案9.26
- C++primer第5版课后练习习题答案9.28
- C++primer第5版课后练习习题答案9.51
- C++primer第5版课后练习习题答案9.52
- C++primer第5版课后练习习题答案7.23
- 《C Primer Plus(第5版)中文版》第7章编程练习第5题
- 《C Primer Plus(第5版)中文版》第6章编程练习第1题
- 《C Primer Plus(第5版)中文版》第6章编程练习第14题
- 《C Primer Plus(第5版)中文版》第6章编程练习第15题
- 《C Primer Plus(第5版)中文版》第6章编程练习第16题
- 《C Primer Plus(第5版)中文版》第7章编程练习第1题
- 《C Primer Plus(第5版)中文版》第7章编程练习第2题
- Math类操作数据
- 使用 Multi-Paxos 协议的日志同步与恢复
- 合唱队形
- C++中数字与字符串之间的转换
- Ajax 入门之 GET 与 POST 的不同 (2)
- C++ Primer 第5版--练习9.47
- jQuery源码阅读笔记
- MyBatis快速入门(一) 搭建环境和单表映射
- GPU与CPU对比测试
- Android中国地图区域检测控件的实现
- Zookeeper Java API使用
- 动态监听localhost无法注册成功
- cdh下kerberos认证问题
- 并查集,battles over cities,路径压缩,优化与封装,无向图连通性