为什么在包含 <string.h> 并使用 std::basic_string 时会出现编译器错误?

ali*_*ius 2 c++ stdstring

当我尝试编译以下代码时:

\n\n
#include <string.h>\nusing namespace std;\ntypedef std::basic_string<char> foostring;\nfoostring foo = "foo";\n
Run Code Online (Sandbox Code Playgroud)\n\n

我收到以下错误:

\n\n
stringtest.cpp:5: error: expected initializer before \xe2\x80\x98<\xe2\x80\x99 token\nstringtest.cpp:6: error: \xe2\x80\x98foostring\xe2\x80\x99 does not name a type\n
Run Code Online (Sandbox Code Playgroud)\n\n

我的编译器是: g++ (Ubuntu 4.4.1-4ubuntu9) 4.4.1
\n我做错了什么?一旦我弄清楚如何使用它,我打算将其与 Windows TCHAR 一起使用以支持 unicode。

\n

GMa*_*ckG 5

标题是<string>,不是<string.h>

没有一个标准库头文件以扩展名结尾。(您正在包含 C header string.h,如果您真正想要的话,它应该包含在 C++ via 中<cstring>。)