【C++学习】文件操作

模式介绍

模式标志 描述
ios::app 追加模式,所有写入都追加到文件末尾。
ios::ate 文件打开后定位到文件末尾。
ios::in 打开文件用于读取。
ios::out 打开文件用于写入。
ios::trunc 如果该文件已经存在,其内容将在打开文件之前被截断,即把文件长度设为 0。

读取文件

#include 
using namespace std;

vector<string> path;
ifstream fin("trainingset.txt");
if(fin.is_open()){
	while(!fin.eof()){
		string line;
		getline(fin,line);
		path.push_back(line);
	}
}
else
	cout<<"open file failed!"<<endl;

你可能感兴趣的:(编程技术,c++,学习,开发语言)