文件流_C++

#include<iostream>
#include<string>
#include<fstream>
#include<vector>
using namespace std;
int main() {
vector<string> V;
vector<string>::iterator itV;
/*cout << “hi” << ends;
cout << “hi” << endl;
string address; //地址
string data; //内容
string data1;
address = “F:\\test.txt”;
ifstream readf;
ofstream writef; //写
writef.open(address); //打开文件
cout << “1:”;
cin>>data; //控制台写入内容 //遇到空格或者回车,表示这个数读取完毕
writef << data<<ends<<ends; //写如入件流 //这个ends产生的空格和设备产生的空格不一样
cout << “2:”;
cin >> data;
writef << data<<endl;
writef.close(); //文件关闭
readf.open(address); //打开文件
while (readf >> data1) //循环读取//遇到”\n”才算结束一个读取
{
V.push_back(data1); //存入向量
}
if (!V.empty()) //输出元素个数
cout << V.size() << endl;
cout << V[0];
readf.close(); //文件关闭*/
ifstream rdf;
string address;
string data;
int num=1;//用于控制换行
address = “F:\\test.txt”;
rdf.open(address);
while (rdf >> data) //读取数据时,遇到空格或回车,则本次读取结束
{
V.push_back(data);
}
if (V.empty())
cout << V.size() << endl;
else
for (itV = V.begin(); itV != V.end(); ++itV,++num)
{

cout << *itV <<” “;
if (num % 2 == 0)
cout << endl;
}
rdf.close();
cout << endl;
system(“pause”);
return 0;
}