-
Notifications
You must be signed in to change notification settings - Fork 1
/
StringOperation.cpp
71 lines (60 loc) · 1.15 KB
/
StringOperation.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<iostream>
#include<string.h>
using namespace std;
/**
* 读到有换行为止
**/
void readLine(){
string word;
while(cin>>word){
cout<<word;
}
}
/**
* 直接读一行
**/
void readALine(){
string word;
getline(cin,word);
if(word.empty()) cout<<"empty"<<endl;
else cout<<"not empty"<<endl;
cout<<"str size is "<<word.size()<<endl;
cout<<"str[i] is "<<word[0]<<endl;
cout<<word;
}
/**
* 单个字符地遍历字符串
**/
void view(){
string word("Hello World");
for(char w:word){
cout<<w<<endl;
}
}
/**
*
**/
void categorize(){
string word;
string digists(100,'\0');
string letters(100,'\0');
string controls(100,'\0');
int d = 0, l = 0, cnt = 0;
getline(cin,word);
for(char c:word){
if(isdigit(c))
digists[d++] = c;
else if(isalpha(c))
letters[l++] = c;
else if(iscntrl(c))
controls[cnt++] = c;
}
cout<<"digists are "<<digists<<endl;
cout<<"letters are "<<letters<<endl;
cout<<"controls are "<<controls<<endl;
}
int main(){
string a = "test";
categorize();
return 0;
}