一、输入流操作

1.read 无格式输入指定字节数

istream& read ( char* pch, int nCount );

istream& read ( unsigned char* puch, int nCount );

istream& read ( signed char* psch, int nCount );

2.get 从流中提取字符,包括空格

int get();

istream& get( char* pch, int nCount, char delim = '\n' );

istream& get( unsigned char* puch, int nCount, char delim = '\n' );

istream& get( signed char* psch, int nCount, char delim = '\n' );

istream& get( char& rch ); istream& get( unsigned char& ruch );

istream& get( signed char& rsch );

istream& get( streambuf& rsb, char delim = '\n' );

3.getline 从流中提取一行字符

istream& getline( char* pch, int nCount, char delim = '\n' );

istream& getline( unsigned char* puch, int nCount, char delim = '\n' );

istream& getline( signed char* psch, int nCount, char delim = '\n' );

4.ignore 提取并丢弃流中指定字符

istream& ignore( int nCount = 1, int delim = EOF );

5.peek 返回流中下一个字符,但不从流中删除

int peek();

6.gcount 统计最后输入的字符个数

int gcount() const;

7.eatwhite 忽略前导空格

void eatwhite();

8.seekg 移动输入流指针

istream& seekg( streampos pos );

istream& seekg( streamoff off, ios::seek_dir dir );

9.tellg 返回输入流中指定位置的指针值

streanpos tellg();

10.operator >> 提取运算符

basic_istream& operator>>( basic_istream& (*pf)(basic_istream&));

basic_istream& operator>>( basic_ios<E, T>& (*pf)(basic_ios<E, T>&));

basic_istream& operator>>( ios_base<E, T>& (*pf)(ios_base<E, T>&));

basic_istream& operator>>( basic_streambuf<E, T> *sb);

basic_istream& operator>>(bool& n);

basic_istream& operator>>(short& n);

basic_istream& operator>>(unsigned short& n);

basic_istream& operator>>(int& n);

basic_istream& operator>>(unsigned int& n);

basic_istream& operator>>(long& n);

basic_istream& operator>>(unsigned long& n);

basic_istream& operator>>(void *& n);

basic_istream& operator>>(float& n);

basic_istream& operator>>(double& n);

basic_istream& operator>>(long double& n);

例子:

 //用get函数从键盘输入字符
void f1(){
char c;
cout<<"Enter first sentence followed by enter\n";
while((c = cin.get())!='\n')
cout.put(c);
cout<<endl; cout<<"Enter second sentence followed by enter\n";
while(cin.get(c)){
if (c == '\n')
break;
cout.put(c);
}
cout<<endl; cout<<"Enter thired sentence followed by enter\n";
char s[];
cin.get(s, );
cout<<s<<endl;
}

输出:

二、输出流

1.put 无格式,插入一个字节

ostream& put(char ch);

2.write 从无格式,插入一字节序列

ostream& write( const char* pch, int nCount );

ostream& write( const unsigned char* puch, int nCount );

ostream& write( const signed char* psch, int nCount );

3.flush 刷新输出流

ostream& flush();

4.seekp 移动输出流指针

ostream& seekp( streampos pos );

ostream& seekp( streamoff off, ios::seek_dir dir );

5.tellp 返回输出流中指定位置的指针

streampos tellp();

6.operstor<< 插入运算符

basic_ostream& operator<<( basic_ostream& (*pf)(basic_ostream&));

basic_ostream& operator<<( basic_ios<E, T>& (*pf)(basic_ios<E, T>&));

basic_ostream& operator<<( ios_base<E, T>& (*pf)(ios_base<E, T>&));

basic_ostream& operator<<( basic_streambuf<E, T> *sb);

basic_ostream& operator<<(const char *s);

basic_ostream& operator<<(char c);

basic_ostream& operator<<(bool n);

basic_ostream& operator<<(short n);

basic_ostream& operator<<(unsigned short n);

basic_ostream& operator<<(int n);

basic_ostream& operator<<(unsigned int n);

basic_ostream& operator<<(long n);

basic_ostream& operator<<(unsigned long n);

basic_ostream& operator<<(float n);

basic_ostream& operator<<(double n);

basic_ostream& operator<<(long double n);

basic_ostream& operator<<(void *n);

例子:

 #include<iostream.h>
void main()
{ cout << "Enter a sentence followed by Enter\n" ;
char s[ ] ;
cin.getline ( s, ) ;
cout.write(s, ) ;
cout<<endl;
}

输出:

三、流错误状态

C++: I/O流详解的更多相关文章

  1. 基于JavaSE阶段的IO流详解

    1.IO流基本概述 在Java语言中定义了许多针对不同的传输方式,最基本的就是输入输出流(俗称IO流),IO流是属于java.io包下的内容,在JavaSE阶段主要学下图所示的: 其中从图中可知,所有 ...

  2. CSS布局之脱离文档流详解——浮动、绝对定位脱离文档流的区别

    1.代码 (1)示例代码1 <!DOCTYPE html> <html lang="zh"> <head> <meta charset=& ...

  3. Spring Cloud Zuul 限流详解(附源码)(转)

    在高并发的应用中,限流往往是一个绕不开的话题.本文详细探讨在Spring Cloud中如何实现限流. 在 Zuul 上实现限流是个不错的选择,只需要编写一个过滤器就可以了,关键在于如何实现限流的算法. ...

  4. [视频播放] HLS协议之M3U8、TS流详解

    本文转载自:<hls之m3u8.ts流格式详解> HLS,Http Live Streaming 是由Apple公司定义的用于实时流传输的协议,HLS基于HTTP协议实现,传输内容包括两部 ...

  5. Spring Cloud限流详解

    转自:https://blog.csdn.net/tracy38/article/details/78685707 在高并发的应用中,限流往往是一个绕不开的话题.本文详细探讨在Spring Cloud ...

  6. Spring Cloud(十二):Spring Cloud Zuul 限流详解(附源码)(转)

    前面已经介绍了很多zuul的功能,本篇继续介绍它的另一大功能.在高并发的应用中,限流往往是一个绕不开的话题.本文详细探讨在Spring Cloud中如何实现限流. 在 Zuul 上实现限流是个不错的选 ...

  7. web前端学习(四)JavaScript学习笔记部分(5)-- 事件流详解

    1.JS事件详解-事件流 1.1.事件流 1.事件流: 描述的是在页面中接受事件的顺序 2.事件冒泡: 由最具体的元素接收,然后逐级上传播至最不具体的节点(文档) 3.事件捕获: 最不具体的节点先接收 ...

  8. IO流详解

    目录 IO流 IO流概述及其分类 IO概念 流按流向分为两种: 流按操作类型分为两种: 常用的IO流类 字节流的抽象父类: 字符流的抽象父类: InputStream & FileInputS ...

  9. Java io流详解四

    转载地址:http://www.cnblogs.com/rollenholt/archive/2011/09/11/2173787.html 写在前面:本文章基本覆盖了java IO的全部内容,jav ...

  10. java IO流详解

    流的概念和作用 学习Java IO,不得不提到的就是JavaIO流. 流是一组有顺序的,有起点和终点的字节集合,是对数据传输的总称或抽象.即数据在两设备间的传输称为流,流的本质是数据传输,根据数据传输 ...

随机推荐

  1. Java 虚拟机-Java内存区域

    简要介绍Java的内存区域: 运行时数据区域 HotSpot虚拟机对象 一.概览 二.运行时数据区域 2.1 程序计数器 Program Counter Register,代表当前线程所执行的字节码的 ...

  2. TLD视觉跟踪算法

    TLD算法好牛逼一个,这里有个视频,是作者展示算法的效果,http://www.56.com/u83/v_NTk3Mzc1NTI.html.下面这个csdn博客里有人做的相关总结,感觉挺好的,收藏了! ...

  3. hihoCoder#1068(RMQ-ST算法)

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho在美国旅行了相当长的一段时间之后,终于准备要回国啦!而在回国之前,他们准备去超市采购一些当地特产——比如汉堡 ...

  4. clone对象的克隆

    用一句简单的话来说就是浅拷贝,只是对指针的拷贝,拷贝后两个指针指向同一个内存空间,深拷贝不但对指针进行拷贝,而且对指针指向的内容进行拷贝,经深拷贝后的指针是指向两个不同地址的指针. 等多 http:/ ...

  5. 【转】 Pro Android学习笔记(八四):了解Package(3):包间数据共享

    目录(?)[-] 共享User ID的设置 共享资源例子 文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件.转载须注明出处:http://blog.csdn.net/flowing ...

  6. 杂项:UUID

    ylbtech-杂项:UUID UUID 是 通用唯一识别码(Universally Unique Identifier)的缩写,是一种软件建构的标准,亦为开放软件基金会组织在分布式计算环境领域的一部 ...

  7. MySQL mysqldump与innobackupex 组合备份

    此脚本,在01点进行一次逻辑全备份,03点进行一次物理全备份,中午12点进行一次增量物理备份 #! /bin/bash #05 01,03,12 * * * mysql /data/mysqldata ...

  8. Windows下.svn文件夹的最简易删除方法(附linux)

    如果想删除Windows下的.svn文件夹,通过手动删除的渠道是最麻烦的,因为每个文件夹下面都存在这样的文件.下面是一个好办法:建立一个文本文件,取名为kill-svn-folders.reg(扩展名 ...

  9. vue中父子组件传递信息实现

    为了能够在父子组件中实现双向控制,需要以下的步骤: 第一步:子组件中挖坑 (1)在需要父组件填充具体内容的地方挖坑,方式为 <slot name="message">& ...

  10. LNMP 1.6 常见的502问题解决

    在nginx上跑discuz,先修改配置文件 cd /usr/local/nginx/conf/vhosts/ vim test.conf server { listen ; server_name ...