cout을 사용하여 문자열을 출력할 수 없는 문제 해결
cout을 사용하여 문자열을 출력할 수 없는 이유는 무엇입니까? 이 문제를 자세히 조사하고 해결책을 제시해 보겠습니다.
코드 조각에서:
<code class="cpp">string text; text = WordList[i].substr(0, 20); cout << "String is : " << text << endl;
다음 오류가 발생합니다.
Error 2 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) c:\users\mollasadra\documents\visual studio 2008\projects\barnamec\barnamec\barnamec.cpp 67 barnamec**
이 오류를 해결하려면 , 필요한 헤더를 포함해야 합니다.
<code class="cpp">#include <string> #include <iostream></code>
수정된 코드는 다음과 같습니다.
<code class="cpp">#include <string> #include <iostream> string text; text = WordList[i].substr(0, 20); cout << "String is : " << text << endl;</code>
이제 cout을 사용하여 문자열을 성공적으로 출력할 수 있습니다.
위 내용은 왜 `cout`을 사용하여 문자열을 출력할 수 없나요?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!