栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

读取文件的四种方式

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

读取文件的四种方式

读取文件的四种方式:

#include
#include
#include 
#include
#include
#include
using namespace std;
using namespace cv;

void test02() {
	ifstream ifs;
	ifs.open("test01.txt", ios::in);
	if (!ifs.is_open()) {
		cout << "读取文件失败" << endl;
		return;
	}
	//第一种读取文件的方式
	//char buf[1024] = { 0 };
	//while (ifs >> buf) {
	//	cout << buf << endl;
	//}

		//第二种读取文件的方式
	//char buf[1024] = { 0 };
	//while (ifs.getline(buf, sizeof(buf))) {
	//	cout << buf << endl;
	//}

	//	第三种读取文件的方式
	

	//第四种读取文件的方式
	char c;//逐个字符读取,效率低下,不推荐
	while ((c = ifs.get()) != EOF){
		cout << c ;
}
	ifs.close();
}
int main() {
	test02();
	system("pause");
	return 0;
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/657284.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号