C++笔记 标准库类型string
程序员文章站
2022-07-15 13:37:53
...
primer C++笔记
标准库类型string
直接初始化和拷贝初始化
string s;
cin >> s;
cout << s << endl;
// hello 输出:hello 自动忽略开头的空白(即空格符、换行符、制表符)
// hello world! 输出:hello
string s1, s2;
cin >> s1 >> s2;
cout << s1 << s2 << endl;
// hello world! 输出:helloworld
string word;
while (cin >> word) //反复读取,直至文件末尾
cout << word << endl; //逐个输出单词,每个单词后面紧跟一个换行
// a b c 0 输出:a\n b\n c\n 0\n
//a 换行 也能输出结果
string line;
//每次读入一整行,直至到达文件末尾
while (getline(cin, line))
cout << line << endl;
下一篇: C++标准库中的String类型
推荐阅读
-
C语言笔记 15_标准库&locale&math&setjmp&signal&stdarg&stddef
-
Python随手笔记之标准类型内建函数
-
Python标准库笔记(11) — Operator模块
-
C++标准库和标准模板库介绍
-
C语言笔记 14_标准库&assert&ctype&errno&float&limits
-
c/c++ 重载运算符 标准库function的用法
-
《从零开始学Swift》学习笔记(Day 71)——Swift与C/C++混合编程之数据类型映射
-
c++ primer(第五版)学习笔记及习题答案代码版(第十四章)重载运算与类型转换
-
C++ string类型的几个典型应用
-
C++标准库笔记:算法--min/max/swap/iter_swap