최근 코딩 테스트 광탈하고 코딩 테스트 관련해서 공부를 더 할 필요성을 느꼈다.
원래는 자바로 보고 있었는데, C++로 하면 효율성이 더 좋아지지 않을까 하는 마음에 다시금 C++을 공부하고 있는 도중 에러가 발생했다.
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
string solution(string my_string) {
vector<string> v {"a", "e", "i", "o", "u"};
string answer = "";
for (const string s : v) {
my_string.erase(remove(my_string.begin(), my_string.end(), s), my_string.end());
}
answer = my_string;
return answer;
}
int main() {
cout << solution("bus") << endl;
cout << solution("nice to meet you") << endl;
}
현재 내가 작성하고 있는 코드이고 remove 부분에서

이러한 에러가 났다.
디버깅을 해보고자 string s 자리에 "u"를 하드코딩해보았더니 정상적으로 작동하는 것을 확인할 수 있었다.
vector v가 string 타입인데, remove에서는 char 타입을 파라미터로 요구했기 때문이었다.
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
string solution(string my_string) {
vector<char> v = {'a', 'e', 'i', 'o', 'u'};
string answer = "";
for (const char s : v) {
my_string.erase(remove(my_string.begin(), my_string.end(), s), my_string.end());
}
answer = my_string;
return answer;
}
int main() {
cout << solution("bus") << endl;
cout << solution("nice to meet you") << endl;
}
vector를 char 타입으로 변경해주니 정상적으로 잘 작동했다.
C++에 대해 공부가 많이 필요할듯...