输入数据将重复的剔除掉,剩下的写到文件中

//测试程序,输入一些数字,插入到一个向量中,如果重复输入则丢弃,最后保证向量中的数字是不重复的
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;
void main()
{
	vector<int> v;
	int x;
	fstream f_bxy;
	f_bxy.open("d:\\test.txt",ios::out);
	while(1)
	{
		cin >> x;
		if(x == 0)
		{
			break;
		}
		if(find(v.begin(),v.end(),x) == v.end())
		{
			v.push_back(x);
		}
	}
	system("pause");
	for(vector<int>::iterator c=v.begin(); c != v.end(); ++c)
	{
		f_bxy << *c << " ";
	}
	f_bxy.close();
}

你可能感兴趣的:(ios,c,测试,iterator,System)