0

これが私の非常に単純な C++ 関数です。

#include <string.h>


void myFunc(void * param)
{
        string command;
}

なぜコンパイルされないのですか?

% CC -c -o testFunc.o testFunc.C
"testFunc.C", line 6: Error: string is not defined.
1 Error(s) detected.
4

2 に答える 2

8

<string.h>は C に由来し、C++ クラスではなく、memcmpや などのC 文字列処理関数を定義します。標準 C++ では、そのヘッダーはであり、クラスは名前空間にあります。strcpystring<string>stringstd

于 2013-08-26T20:37:56.023 に答える
6

まさにそれがあなたに言っている理由でコンパイルされていません:

Error: string is not defined.

に変更<string.h><string>ます。

また、正しい名前空間を使用していることを確認してください。これは次の方法で実行できます。

using std::string;

また

std::string command;

詳細説明:

  • <string.h>CのC文字列用です。
  • <cstring>C++ の C 文字列用です。
  • <string>は C++ 用ですstd::string
于 2013-08-26T20:38:40.750 に答える