I/O类 & 文件读写操作
来源:互联网 发布:sql语句常见面试题 编辑:程序博客网 时间:2024/05/20 06:23
fstream 和 stringstream 都是继承自类iostream
输入类ifstream、istringstream都继承自istream
输出类ofstream、ostringstream都继承自ostream;
因此,可以在istream对象上执行的操作,也可以在ifstream和istringstream上执行。其他类也有相同的情况。
fstream,文件I/O
#include <fstream>ofstream //文件写操作 内存写入存储设备 ifstream //文件读操作,存储设备读区到内存中fstream //读写操作,对打开的文件可进行读写操作
iostream控制台I/O
#include<iostream>istream //从流中读取数据ostream //向流中写入数据iostream //读写流
stringstream string流
#include<sstream>istringstream //从string读数据ostringstream //向string中写数据stringstream //既可读string,也可写string
可以使用istringstream**将一个大字符串拆分成若干个单个Word**;这是最常用的情况;
#include <iostream>#include<fstream>#include<sstream>using namespace std;int main(){ string s="1234 256457"; string str1; istringstream strm(s);//将字符串读到strm中 while(strm>>str1) //拆分出每个Word,当没有可拆分的Word会返回null,跳出循环 { cout<<str1; } return 0;}
阅读全文
0 0
- I/O类 & 文件读写操作
- Matlab 文件读写(I/O)和字符串操作常用命令
- JAVA exception异常处理+I/O操作读写文件 笔记
- JAVA exception异常处理+I/O操作读写文件 笔记
- 文件的读写(I/O)操作总结
- Java文件读写操作(file I/O)
- java I/O 读写文件
- C++ 文件读写 I/O
- I/O流 文件读写
- 文件I/O流读写
- 文件I/O操作
- 文件I/O操作
- 文件I/O操作
- I/O 文件操作
- 文件I/O操作
- I/O 文件操作
- 文件I/O操作
- 文件I/O操作
- 回溯法练习笔记
- intellij idea打包war包
- windows 10 安装pygame
- 冒泡排序 二分查找 快速排序 线性查找
- Python数据分析与展示(一)(基于北理MOOC)
- I/O类 & 文件读写操作
- 【算法入门】广度/宽度优先搜索(BFS)
- java swing实现Calculator
- Android应用程序入口源码解析
- unbuntu 16.04搭建gitlab
- 基于分布式环境下限流系统的设计
- HDOJ2113 Secret Number
- Tomcat执行流程!
- java 的常用类 io流 及其他