Created
January 7, 2016 02:42
-
-
Save zhangzhiqiangcs/0d1d62f884cd4f919234 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<string> | |
using namespace std; | |
void find_char(string &s, const string &chars){ | |
cout << "在" << s << "中查找" << chars << "中字符" << endl; | |
string::size_type pos = 0; | |
while ((pos = s.find_first_of(chars, pos)) != string::npos) | |
{ | |
cout << "pos: " << pos << ", char: " << s[pos] << endl; | |
pos++; | |
} | |
} | |
int main() { | |
string s = "ab2c3d7R4E6"; | |
cout << "查找所有数字" << endl; | |
find_char(s, "0123456789"); | |
cout << endl << "查找所有字母" << endl; | |
find_char(s, "abcdefghijklmnopqrstuvwxyz"\ | |
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"); | |
system("pause"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment