C2059语法错误'string'?

Ben*_*avi 7 c c++

extern "C" 
{
#endif
#include <stdint.h>
#include <limits.h>
#include "attributes.h"
}
#endif
Run Code Online (Sandbox Code Playgroud)

我添加了extern "C" { } 然后我得到了C2059 string错误所以我试图使用#endif,现在我有另外4个错误.

Error   1   error C2059: syntax error : 'string'    d:\c-sharp\c++ 
compiling\consoleapplication7\consoleapplication7\libavutil\rational.h 31 1
ConsoleApplication7
Run Code Online (Sandbox Code Playgroud)

我该如何修复此字符串错误?

sim*_*onc 20

猜测,你是否从C源文件中包含此代码?

extern "C" {只有C++才需要(或理解)警卫.您可以从C文件中省略它们,应该将它们包含在C++文件中,并且应该__cplusplus在头文件中使用ifdef来保护它们 .

#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <limits.h>
#include "attributes.h"
#ifdef __cplusplus
}
#endif
Run Code Online (Sandbox Code Playgroud)

  • 您通常不会将标题放在`extern"C"{}`部分中. (3认同)