C2059 语法错误 'string' ?

C2059 syntax error 'string' ?

本文关键字:string 语法 错误 C2059      更新时间:2023-10-16
extern "C" 
{
#endif
#include <stdint.h>
#include <limits.h>
#include "attributes.h"
}
#endif

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

Error   1   error C2059: syntax error : 'string'    d:c-sharpc++ 
compilingconsoleapplication7consoleapplication7libavutilrational.h 31 1
ConsoleApplication7

如何修复这个字符串错误?

猜测,您是否包括来自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