c++读取文件

来源:互联网 发布:自然语言处理算法面试 编辑:程序博客网 时间:2024/06/04 18:15
#include <fstream>#include<iostream>using namespace std;/*读取文件中的数据打开文件读取数据的方法和输出数据到文集中的方法基本上是一样的,同样也需要5个步骤:包含fstream头文件:#include <fstream>建立ifstream对象:ifstream read;将对象与文件关联:read.open(“test.txt”);使用该对象读取文件test中的数据到数组temp中:read.getline(temp,100);关闭与文件的连接:read.close();*/int main() {    ifstream read("a.txt");    char temp[1000];    read.getline(temp,100);//把文件中的内容读到字符数组temp中    read.close();    cout<<temp<<endl;//输出到显示屏上     return 0;}
0 0