IO
来源:互联网 发布:开淘宝店铺怎么描述 编辑:程序博客网 时间:2024/06/15 03:41
getline按行读取内容(C++)
•功能:–从输入流中读入字符,存到string变量–直到出现以下情况为止:•读入了文件结束标志•读到一个新行•达到字符串的最大长度–如果getline没有读入字符,将返回false,可用于判断文件是否结束#include<stdio.h>#include<string.h>#define INFO_MAX_SZ 255#include <fstream>#include <string>#include <iostream>using namespace std;void readLine(){ ifstream f("t.txt", ios::in); string buff; while(getline(f, buff)) cout << buff << endl;}int main(){ readLine(); return 0;}
fgets读取行(C)
#include<stdio.h>#include<string.h>#define INFO_MAX_SZ 255#include <fstream>#include <string>#include <iostream>using namespace std;void fgetsLine(){ FILE* f = fopen("t.txt", "r"); if(f == NULL) cout << "打开文件失败" << endl; char ch[1024]; while(fgets(ch, 1024, f)) { cout<< ch; }}int main(){ fgetsLine(); return 0;}
按字段读取(C++)
#include<stdio.h>#include<string.h>#define INFO_MAX_SZ 255#include <fstream>#include <string>#include <iostream>using namespace std;void reader(){ ifstream f("t.txt", ios::in); if(!f.is_open()) cout << "文件打开失败" << endl; while(f != NULL) { string ch; f >> ch; if(ch == "") break; cout << ch << endl; }}int main(){ reader(); return 0;}
0 0
- IO
- IO
- io
- IO
- io
- IO
- io
- IO
- IO
- IO
- io
- IO
- IO
- IO
- IO
- IO
- IO
- IO
- js form onsubmit 表单提交
- 1.2.5对指针使用const限定符
- 关于图像特征提取
- 《健康时报》:请不要随便输液
- 二维图形变换
- IO
- 用Java根据错误值解析出错误类型和错误码
- android之旅4: XML方式读写数据与文件创建
- Android监听软键盘弹出与收起
- Linux下配置Caffe及其Python接口全过程记录(Ubuntu15.10_amd64+CUDA7.5)及训练mnist数据集
- 窗口刷新问题(WMPAINT、BeginPaint、EndPaint的说明)
- C51中变量的存储器类型有
- 心上莲花:见闻两则——杀业的果报
- C读取和写入一个二维数组