我正在尝试使用-std = c ++ 11的g ++ 4.8.2版中的snprintf编译代码,但没有成功。 为什么g ++不能识别snprintf?我可以在使用snprintf和c ++ 11时克服这个问题吗?
我得到了以下内容:
make all Building file: ../src/cppHWtest.cpp Invoking: Cygwin C++
Compiler g++ -std=c++11 -D"hash_map=unordered_map" -O0 -g3 -Wall -c
-fmessage-length=0 -MMD -MP -MF"src/cppHWtest.d" -MT"src/cppHWtest.d" -o "src/cppHWtest.o" "../src/cppHWtest.cpp" cygwin warning: MS-DOS style path detected: C:\Users\poudyal\workspace\cppHWtest\Debug
Preferred POSIX equivalent is:
/cygdrive/c/Users/poudyal/workspace/cppHWtest/Debug CYGWIN
environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames ../src/cppHWtest.cpp: In function 'int main()':
../src/cppHWtest.cpp:20:35: error: 'snprintf' was not declared in this
scope snprintf(buff, 10, "%s", "Hell O");
^ make: *** [src/cppHWtest.o] Error 1 src/subdir.mk:18: recipe for target 'src/cppHWtest.o' failed
**** Build Finished ****
答案 0 :(得分:6)
将模式切换为-std=gnu++11
的可能性较小的解决方案是-U__STRICT_ANSI__
。这将在stdio.h:234(GCC 4.8.3)启用#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L)
。