要求:
1 分离字符串里的大小写,数字,符号
代码如下:
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string s("ab2c3d7R4E6");
string numberics("0123456789");
string alphabetic("abcdefghijklmnopqrstuvwxyz");
string alphabetic1("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
string::size_type pos= 0;
// 查找数字 从s的 0 位置开始查找 npos表示string的末尾
cout<<"字符串:"<<s<<endl;
cout<<"-------数字--------"<<endl;
while((pos=s.find_first_of(numberics,pos))!=string::npos)
{
cout<<"s{"<<pos<<"}="<<s[pos++]<<endl;
}

本文介绍如何使用C++将字符串中的大小写字母、数字和符号进行分离。通过示例代码展示了如何分别获取数字、小写字母、大写字母以及不包含数字的字符。
订阅专栏 解锁全文
2652

被折叠的 条评论
为什么被折叠?



