如何在g ++ -std = c ++ 11版本4.8.2中使用snprintf()

vjk*_*ktm 5 printf cygwin g++ c++11

我正在尝试使用-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 ****
Run Code Online (Sandbox Code Playgroud)

Pav*_*nko 6

可能-std=gnu++11是比切换模式更少侵入性的解决方案-U__STRICT_ANSI__.这将#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L)在stdio.h:234(GCC 4.8.3)启用.

  • 这适用于Cygwin上的`-std = c ++ 11`. (2认同)