C++中字符串I/O
来源:互联网 发布:python line.split 编辑:程序博客网 时间:2024/05/22 11:57
可以使用cout和插入操作符<<来输出string对象,这和处理其他类型的数据是一样的;
可以使用cin和提取操作符>>时,方式和其他数据一样,但要注意:>>会忽略最初的空白字符,并在遇到更多的空白字符时停止读入!
// String.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include<iostream>#include<conio.h>#include<string>int main(int argc, char* argv[]){using namespace std;string line;cout<<"Enter a line ofinput :";cin>>line;cout<<"Output :";cout<<line;cout<<endl;return 0;}
如果要想读取一整行,可以使用getline()函数,注意:这个getline()不是成员函数!
// String.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include<iostream>#include<conio.h>#include<string>int main(int argc, char* argv[]){using namespace std;string line;cout<<"Enter a line ofinput :";getline(cin,line);cout<<"Output :";cout<<line;cout<<endl;return 0;}
注意:此时未忽略前面的空白符!
- C++中字符串I/O
- C++I/O操作
- c++I/O流
- 标准 C I/O
- C++I/O技术
- c++I/O操作
- C之I/O
- C标准I/O
- 标准 C I/O
- 标准C I/O
- objective-c I/O
- C++I/O输入输出
- java中字符串与文本I/O流
- 字符串与文件I/O
- C语言中I/O流的一些疑惑
- 学习C字符串表示和字符串I/O(CprimerPlus11.1)的心得
- 基本文件的I/O --从字符串中读取字符&向字符串中写入字符
- C标准I/O操作
- 在mac上安装nginx
- spring定时任务之quartz
- NHibernate Linq 的 join (联合查询) 的例子
- Activity 的生命周期
- Kinect for Windows SDK开发入门(一):开发环境配置
- C++中字符串I/O
- 二叉树的遍历
- VC中CDC与HDC的区别以及二者之间的转换
- linux下svn命令大全
- 【区间动规】 MM不哭
- 寂寞红尘里,你在等待谁的安慰
- CKEditor+CKFinder
- Linux locale 缺失和安装
- 关于HashMap和LinkedHashMap的工作心得