erase を使ってみる (C++)
C++
Published: 2019-12-29

やったこと

erase を使ってみます。

確認環境

$ g++ --version
g++ (Homebrew GCC 9.2.0) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

調査

test.cpp

#include <bits/stdc++.h>
using namespace std;

int main() {
    string t = "abcdefg";
    t.erase(1, 2);
    cout << t << endl;

    vector<int> v = {1, 3, 5, 7};
    v.erase(v.begin() + 2);
    for (auto iter = v.begin(); iter != v.end(); iter++) {
        cout << *iter << endl;
    }
}

出力結果

adefg
1
3
7

参考