C++ primer 学习笔记——字符串
2015-11-03 16:52
99 查看
初始化和定义
字符串操作
字符串上字符操作
下标运算符 [],参数类型string::size_type
string s1; string s2=s1; string s1("hello");//直接初始化 string s2="hello";//拷贝初始化
字符串操作
string s; s.empty(); s.size();//返回值类型string::size_type getline(cin,s);//参数:流参数,字符串;返回s 的流参数 s1+s2;//+俩侧必须有一项为string对象,字符串面值不是 s1==s2;s1>s2;
字符串上字符操作
for(declaration:experssion) statement
下标运算符 [],参数类型string::size_type
#include<iostream> #include<string> #include<cctype> using std::string; using std::cout; int main() { string s("hello world "); decltype(s.size()) punch_cnt = 0;//设置punch_cnt的类型为string::size_type //for (auto c : s) //{ // if (ispunct(c)) // ++punch_cnt; //} for (auto &c : s) c = toupper(c); cout << s; cout << punch_cnt; return 0; }
相关文章推荐
- 字节对齐
- C++标准转换运算符reinterpret_cast
- C++单元测试一:并非看上去那么简单——几个很实际的问题
- 使用C++复制文件
- cppunit使用详解
- 在使用cppunit,搭建测试环境时遇到的问题以及解决办法(仅供参考)
- C++设计模式[二]单例模式
- 算法学习笔记
- Effective C++读书笔记-----术语
- 黑马程序员-------C语言回顾-整型变量修饰符和一维数组
- 日志库EasyLogging++学习系列(10)—— 日志文件滚动
- C语言和设计模式(策略模式)
- 第一次写程序
- c语言学习之基础知识点介绍(十二):结构体的介绍
- 创建 Win32 应用程序 (C++)
- C++primer第五版第一章学习笔记
- 使用const引用传递来提高效率
- <Effective C++>读书笔记-7
- C++ 强制类型转换 static_cast<new_type>(expression)
- 在c# 下如何调试c++的dll