취미생활

[C++] 에러 해결 ‘%s’ expects argument of type ‘char*’, but argument 2 has type ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} 본문

컴퓨터/에러 해결

[C++] 에러 해결 ‘%s’ expects argument of type ‘char*’, but argument 2 has type ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’}

달다달아 2022. 11. 5. 03:07

해당 에러는 printf format 에 std::string 문자를 입력해서 나오는 에러다.

 

printf는 c 기반이고 std::string 는 c++ 기반이라 호환을 하지 않는다.

 

그러므로 다음과 같이 써주자.

printf("%s\n", str.c_str());

 

Comments