使用c++ json库时报错:
https://github.com/nlohmann/json.git
“_snprintf”: 不是“std”的成员
原因
在VS2015前,Windows系统头文件并没有定义snprintf宏,所以cocos2d在CCStdC-win32.h文件做了如下定义
#define snprintf _snprintf
而VS2015开始在系统头文件中又定义了snprintf宏,所以就出现了重定义冲突。
解决
在cocos2d的CCStdC-win32.h文件中注释以下这行,如下:
//#define snprintf _snprintf
这两个是一样的:
#if defined(_MSC_VER) && _MSC_VER < 1500 // VC++ 8.0 and below
#define snprintf _snprintf
#include "json.hpp"
using json = nlohmann::json;
#endif
最后没解决,换jsoncpp后解决了。