遍历String 并进行相关操作

来源:互联网 发布:自我测评软件 编辑:程序博客网 时间:2024/06/11 14:16

string在c++中也有举足轻重的地位

相对于字符数组

string有着更加灵活方便而又人性化的操作

使用起来便快速

且熟练掌握之后更是能使用的出神入化

代码仅供自己学习使用


代码如下


#if 0//遍历string并进行相关操作 #include#include#includeusing namespace std;bool if_upper(string &s);void ch_toupper(string &s);int main(){string s;cin >> s;if (if_upper(s)){cout << "s含有大写子母" << endl;cout << "大写字母转换。。。" << endl;ch_toupper(s);cout << s << endl;}elsecout << "s不含大写字母" << endl;return 0;}//判断string是否含有大写字母bool if_upper(string &s){for (auto &c:s){if (c >= 'A' && c <= 'Z'){return true;}}return false;}//string中大写字母转换小写void ch_toupper(string &s){for (auto &c : s){c = toupper(c);}}#endif

0 0