본문 바로가기
C++ 언어

C++에서 Vector를 사용하여 문자열 정력하기(중복테이타 제외)

by treeCoder 2021. 9. 10.

C++에서 Vector를 사용하여 문자열 정렬하기이다.

중복 데이타는 제외된다.

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {

    string line;

    vector <string> vec;
    vec = vector<string>();

    while( getline(cin, line) ) {
        vec.push_back(line);
    }

    sort(vec.begin(), vec.end());
    auto last = unique(vec.begin(), vec.end());
    
    vec.erase(last, vec.end());


    for ( const auto &i : vec ) {
        cout << i << endl;
    }
}


/* ******************************************
 *
 *    T        // I'm copying this
 *    T&       // I'm modifying this
 *    const T& // I'm reading this
 *
 * *****************************************/

/*

Array
Linkedvec<T>
vec<T>
Stack<T>

Queue<T>
Dictionary<K,T>
SortedDictionary<K,T>
HashSet<T>

SortedSet<T>

*/

댓글