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 中国語 Web サイトの他の関連記事を参照してください。