我是靠谱客的博主 坚定哈密瓜,这篇文章主要介绍C++ primer ——3.2.3节,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//3.6 #include<iostream> #include<string> #include<cctype> using std::string; using std::cout; int main() { string s("hello"); for (int index = 0; index < s.size(); index++) s[index] = 'T'; cout << s; return 0; }
复制代码
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
//3.10 #include<iostream> #include<string> using std::cout; using std::string; using std::endl; int main() { string s("hello,world !"); for (string::size_type index = 0; index < s.size(); index++) { if (ispunct(s[index])) { string::size_type n = index; for (; n < s.size() - 1;n++) s[n] = s[n + 1]; } cout << s[index] << endl; } cout << s; return 0; }//用数组存在BUG如何解决
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<iostream> #include<string> using std::cout; using std::string; int main() { string s("hello,world!"); for (auto c : s) { if (!ispunct(c)) { cout << c; } } return 0; }

最后

以上就是坚定哈密瓜最近收集整理的关于C++ primer ——3.2.3节的全部内容,更多相关C++内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(77)

评论列表共有 0 条评论

立即
投稿
返回
顶部