C++代码笔记(1)string搜索操作——find()
2017-03-18 23:16
525 查看
Reference Book: 《C++ Primer》
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
P327练习9.47:编写程序,查找string中的每个数字字符,然后查找其中每个字母字符。第一个用find_first_of,第二个用find_first_not_of。
#include <iostream>
#include <string>
using namespace std;
int main()
{
string numbers("0123456789"), name("ab2c3d7R4E6");
string::size_type pos = 0;
while((pos = name.find_first_of(numbers, pos)) != string::npos)
{
cout << "Found first number at index: " << pos
<< " element is " << name[pos] << endl;
++pos;
}
pos = 0;
while((pos = name.find_first_not_of(numbers, pos)) != string::npos)
{
cout << "Found first character at index: " << pos
<< " element is " << name[pos] << endl;
++pos;
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
P327练习9.47:编写程序,查找string中的每个数字字符,然后查找其中每个字母字符。第一个用find_first_of,第二个用find_first_not_of。
#include <iostream>
#include <string>
using namespace std;
int main()
{
string numbers("0123456789"), name("ab2c3d7R4E6");
string::size_type pos = 0;
while((pos = name.find_first_of(numbers, pos)) != string::npos)
{
cout << "Found first number at index: " << pos
<< " element is " << name[pos] << endl;
++pos;
}
pos = 0;
while((pos = name.find_first_not_of(numbers, pos)) != string::npos)
{
cout << "Found first character at index: " << pos
<< " element is " << name[pos] << endl;
++pos;
}
}
相关文章推荐
- C++ Primer 学习笔记——顺序容器的string操作
- [DLL]模仿C++中INI文件代码操作习惯的XML配置文件类
- C++中操作数据库的几段代码
- C++ 字符(char)与字符串(string)操作
- 循环队列的定义、入队、出队等操作 C++代码实现
- 顺序栈的定义、初始化、出栈、入栈等操作 C++代码实现
- 代码阅读总结之ASP.NET StartKit TimeTracker(QueryString之改进笔记)
- Windows服务用C++代码实现的一些操作-1:修改服务启动类型
- C++学习笔记:IO操作
- c++学习笔记-bitset操作
- SilverLight学习笔记--如何在xaml文件中操作用户在后台代码定义的类(2)--示例篇:创建一个登录控件(原创)(转载本文请注明出处)
- C/C++ 中的一些字符操作函数(不是std::string)
- C/C++学习笔记2 - cin深入分析(上) - cin输入操作处理(原创)
- RHCE课程-RH033Linux基础笔记七之文件的搜索及高级文件权限和用户、组操作 推荐
- c++代码测试-std::string元素
- c和c++代码精粹 学习笔记
- 这么详细的分类 VC/C++源代码网站你见过没有? VC/C++中的每一个方法,每一个操作,每一个头文件,每一个函数,每一个类.每一个属性,每一个事件都有相应的范例代码
- C/C++中strlen(),strcpy(),strcat()以及strcmp()的代码实现--学习笔记
- C++学习笔记:IO操作
- 二分搜索代码(c++)