当我尝试编译以下代码时:
#include <string.h>
using namespace std;
typedef std::basic_string<char> foostring;
foostring foo = "foo";
我收到以下错误:
stringtest.cpp:5: error: expected initializer before ‘<’ token
stringtest.cpp:6: error: ‘foostring’ does not name a type
我的编译器是:g++ (Ubuntu 4.4.1-4ubuntu9) 4.4.1
我究竟做错了什么?一旦我弄清楚如何使用它,我打算将其与 Windows TCHAR 一起使用以支持 unicode。
标题是
<string>
,而不是 <string.h>
。
所有标准库头文件都不以扩展名结尾。 (您正在包含 C 头文件
string.h
,如果您真正想要的话,它应该通过 <cstring>
包含在 C++ 中。)