C++ Primer笔记(一):字符串、向量和数组
2014-11-21 17:53
211 查看
3.1 命名空间
using namespace::name;using namespace::std
using std::cin
……
头文件不应该包含using
3.2 类型string
getline(cin, str); str.empty(); str.size();
size()返回类型为UINT,不能与int比较,当int为负时出错
string对象只能和string对象或字面值相加
循环处理
for(auto c : str) {} for(auto &c : str) {}
习题3.2.3
#include "stdafx.h" #include <iostream> #include <string> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { string str; cout << "3.6" << endl; str = "aruew32413aefjewoiroqw1231./awrfwer"; cout << str << endl; for (auto &i : str) { i = 'X'; } cout << str << endl; cout << "3.7" << endl; str = "aruew32413aefjewoiroqw1231./awrfwer"; cout << str << endl; for (auto i : str) { i = 'X'; } cout << str << endl; cout << "3.10:Enter a string including punctuation." << endl; getline(cin, str); for (auto i : str) if (!ispunct(i)) cout << i; cout << endl; cout << "3.11" << endl; const string s = "hello"; for (auto &i : s) { cout << typeid(i).name() << endl; break; } return 0; }
待续……
相关文章推荐
- (三)字符串、向量、数组
- 第3章 字符串、向量和数组
- C++ primer 读书笔记(第3章)字符串、向量和数组
- 字符串、向量和数组
- C++Primer第五版 第3章 字符串、向量和数组(练习解答)
- C++ Primer 学习笔记(第三章:字符串、向量和数组)
- Java数组、向量和字符串
- 第三章 字符串、向量和数组
- 【c++ primer读书笔记】【第3章】字符串、向量和数组
- 《C++primer(第五版)》学习之路-第三章:字符串、向量和数组
- 数组、字符串、向量与哈希表
- 《C++ Primer(第5版)》学习笔记:第3章 字符串、向量和数组
- 三、字符串、向量和数组
- 字符串 向量 数组
- C++ Primer学习总结 第3章 字符串,向量和数组
- java学习笔记六——数组、向量、字符串
- c++11(2):字符串、向量和数组
- 数组、字符串、向量、哈希表1
- c++primer要点-字符串、向量和数组
- 【c++ primer读书笔记】【第3章】字符串、向量和数组