C++文件操作-读文件
Posted 行码阁119
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C++文件操作-读文件相关的知识,希望对你有一定的参考价值。
# include<iostream>
# include<fstream>
# include<string>
using namespace std;
//文本文件的读文件
int test01()
{
//1、包含头文件
//2、创建流对象
ifstream ifs;
//3、打开文件判断是否打开成功
ifs.open("test.txt",ios::in);
if (!ifs.is_open()) //文件打开失败:路径失败
{
cout << "文件打开失败" << endl;
return 0;
}
//4、读数据
//第一种
//char buf[1024] = { 0 };
//while (ifs >> buf)
//{
// cout << buf << endl;
//}
//第二种
//char buf[102
以上是关于C++文件操作-读文件的主要内容,如果未能解决你的问题,请参考以下文章