C++学习点滴
最近加入一個C++的學習群,群里免不了有些網友提問題。我也正好學習一下。把一些問題,一些小程序記錄下來,讓自己的C++水平慢慢提上來......
函數功能:
把輸入的字符串中的標點符號去掉之后輸出來,循環執行
如果輸入的字符串沒有標點符號,他就輸出Nopunctuation character in the string ?!
?1#include?<string>?2#include?<cctype>
?3
?4int?main()
?5{
?6?string?s,result_str;
?7?bool?has_punct;
?8?char?ch;
?9?cout<<"Enter?a?string:?"<<endl;
10?while(getline(cin,s))
11?{
12??has_punct=false;
13??result_str?=?"";
14??for(string::size_type?index=0;index!=s.size();index++)
15??{
16???ch=s[index];
17???if(ispunct(ch))
18???{?
19????has_punct=true;
20???}
21???else
22????result_str+=ch;
23??}
24??if(has_punct)
25???cout<<"Result:?"<<endl<<result_str<<endl;
26??else
27??{
28???cout<<"Nopunctuation?character?in?the?string??!"<<endl;
29???//return?-1;
30???continue;
31??}
32??
33?}
34?return?0;
35}
36
轉載于:https://www.cnblogs.com/tianyige/archive/2009/04/26/1444028.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
- 上一篇: 语文高考识记现代汉字的字形【转】
- 下一篇: 关于ArcGIS的文件格式