#include<iostream>#include<fstream>#include<string>#include<vector>using namespace std;int main() {unsigned int i, j;string filename = "Test.txt";fstream fin;fin.open(filename.c_str(), ios::in);vector<string> v;string tmp;while (fin >> tmp){v.push_back(tmp);}for (i = 0; i < v.size(); i++) {for (j = 0; j < v.size(); j++) {int m = j - 1;if (v[i] == v[j]) v.erase(j-1,j);}}for (auto x : v)cout << x << endl;getchar();getchar();return 0;}
1 回答

慕工程0101907
TA貢獻1887條經(jīng)驗 獲得超5個贊
v.erase(j-1,j);
有兩個錯誤
越界
用法錯誤
正確的用法為
vector<string>::iterator t = v.begin();//相當(dāng)于取數(shù)組第一個元素
v.erase(t);//刪除
- 1 回答
- 0 關(guān)注
- 189 瀏覽
添加回答
舉報
0/150
提交
取消