我试图编译使用g ++的版本4.8.2中的snprintf和-std = C++ 11的代码,但没有成功。 为什么g ++不识别snprintf?我仍然可以在使用snprintf和C++ 11的时候克服这个问题吗?如何在g ++中使用snprintf()-std = C++ 11版本4.8.2
我有以下几点:
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 ****
[此cygwin邮件列表归档线程](http://cygwin.com/ml/cygwin/2012-04/msg00140.html)是关于导致'snprintf'不被声明为' -std = C++ 0x'。建议的解决方法是使用'-std = gnu ++ 0x'代替。仅仅为了这个,试试'-std = gnu ++ 11',看看会发生什么。 – Casey
工作正常!我也有#include –
vjktm
我现在发现矢量有同样的问题。 vector <>很好-std = C++ 11 –
vjktm