Std关于文件处理函数

来源:互联网 发布:护士不雅视频网络疯传 编辑:程序博客网 时间:2024/04/28 02:51

#include "stdafx.h"

#include <string>

#include <iostream>

#include <algorithm>

#include <vector>

#include <fstream>

#include <assert.h>

#pragma warning(disable: 4786)

using namespace std;

 

 

 

int main(){

ifstream in("name.txt");

ofstream out("nameout.txt");

string personStr;

vector<string> vect;

//访问文件

while(getline(in, personStr, '/n'))

{

vector<string>::iterator iter;

//截出Name

string name=personStr.substr(0, personStr.find(' '));

//看看重复名字没有,不重复保存

iter=find(vect.begin(),vect.end(),name);

if (iter!=vect.end())

{

continue;

}else

{

vect.push_back(name);

  }

}

//排序

sort(vect.begin(), vect.end());

 

//输出到文件中

vector<string>::iterator it;

for (it=vect.begin();it!=vect.end();it++)

{

cout<<*it<<endl;

out<<*it<<endl;

}

 

 

return 0;

原创粉丝点击