ratehog   2년 전

하기 소스 코드에서 케이스 1은 컴파일오류없이 정답처리 되었으나, 케이스 2는 컴파일오류가 나는 이유가 궁금합니다.

오류 내용

note: candidate function not viable: no known conversion from 'value_type' (aka 'char') to 'const string' (aka 'const basic_string<char, char_traits<char>, allocator<char>>') for 1st argument
_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = nullptr, int __base = 10);

zenith82114   2년 전

오류 메시지에 나와 있는 것처럼, char는 std::string으로 자동으로 변환되지 않습니다. 첫 번째 코드처럼 명시적으로 임시 string을 만들면 해결됩니다.

댓글을 작성하려면 로그인해야 합니다.