一、输入流操作

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;
}

输出:

三、流错误状态

最新文章

  1. ElasticSearch实战-日志监控平台
  2. CSS3之渐变效果
  3. linux相关解压命令
  4. mysql数据文件迁移到新的硬盘分区的方法
  5. 用php和imagemagick来处理图片文件的上传和缩放处理
  6. MIME (Multipurpose Internet Mail Extensions) 是描述消息内容类型的因特网标准
  7. 接口登录CSDN发布博客---封装方法,使用unittest框架
  8. AngularJS学习之旅—AngularJS SQL(十二)
  9. javascript的ES6学习总结(第一部分)
  10. 20175325 MyCP (课下作业,必做)
  11. 【redis】redis配置文件参数解析
  12. CSS之边框
  13. Java 学习札记(二)TomCat安装配置
  14. Win10系列:VC++数据绑定
  15. Myelipse中xml约束文件的导入(以spring为例)
  16. HDU 1069 Monkey and Banana(最大的单调递减序列啊 dp)
  17. GDB常用命令使用说明(一)
  18. 求两点之间距离 C++
  19. BlueMind 3.0.17 发布,消息和协作平台
  20. CF 833 B. The Bakery

热门文章

  1. WINRAR4.2破解方式或注册码
  2. unix下网络编程之I/O复用(三)
  3. 如何修改MAC自带的PHP的版本?
  4. HDU1576(扩展欧几里得)
  5. bmp图片格式及读取
  6. k8s cookbook读书笔记 第二章
  7. MySQL中varchar类型排序
  8. hadoop job -kill 与 yarn application -kii(作业卡了或作业重复提交或MapReduce任务运行到running job卡住)
  9. js-tree坑
  10. .NET回归 HTML----超文本标记语言(暂时无图)