64,637
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
using namespace std;
struct Data {
string s;
int number;
};
bool
pred(const Data &a)
{
}
int
main()
{
vector<Data>m_data;
vector<Data>::iterator it1, it2;
vector<Data>::const_iterator it;
Data temp;
bool flag;
temp.s = "1234";
temp.number = 1;
m_data.push_back(temp);
temp.s = "12C7";
temp.number = 2;
m_data.push_back(temp);
temp.s = "123F";
temp.number = 3;
m_data.push_back(temp);
temp.s = "1234";
temp.number = 4;
m_data.push_back(temp);
temp.s = "1234";
temp.number = 5;
m_data.push_back(temp);
temp.s = "123F";
temp.number = 6;
m_data.push_back(temp);
for (it = m_data.begin(); it != m_data.end(); ++it) {
cout << it->s << ',' << it->number << endl;
}
cout << endl;
for (it1 = m_data.begin(); it1 != m_data.end(); ) {
flag = false;
it2 = it1;
advance(it2, 1);
for ( ; it2 != m_data.end(); ++it2) {
if (it2->s == it1->s) {
flag = true;
it1 = m_data.erase(it1);
break;
}
}
if (!flag) {
++it1;
}
}
for (it = m_data.begin(); it != m_data.end(); ++it) {
cout << it->s << ',' << it->number << endl;
}
cout << endl;
return 0;
}