forked from jieniyimiao/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex9_47_2.cpp
34 lines (29 loc) · 1.04 KB
/
ex9_47_2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//
// ex9_47_2.cpp
// Exercise 9.47
//
// Created by pezy on 12/5/14.
// Copyright (c) 2014 pezy. All rights reserved.
//
// @Brief Write a program that finds each numeric character
// and then each alphabetic character in the string "ab2c3d7R4E6".
// Write two versions of the program. The first should use find_first_of,
// and the second find_first_not_of.
// @Version find_first_not_of
#include <string>
#include <iostream>
using std::string; using std::cout; using std::endl;
int main()
{
string numbers{"123456789"};
string alphabet{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"};
string str{"ab2c3d7R4E6"};
cout << "numeric characters: ";
for (string::size_type pos = 0; (pos = str.find_first_not_of(alphabet, pos)) != string::npos; ++pos)
cout << str[pos] << " ";
cout << "\nalphabetic characters: ";
for (string::size_type pos = 0; (pos = str.find_first_not_of(numbers, pos)) != string::npos; ++pos)
cout << str[pos] << " ";
cout << endl;
return 0;
}