2013-11-22 92 views
5

我试图编译使用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 **** 
+3

[此cygwin邮件列表归档线程](http://cygwin.com/ml/cygwin/2012-04/msg00140.html)是关于导致'snprintf'不被声明为' -std = C++ 0x'。建议的解决方法是使用'-std = gnu ++ 0x'代替。仅仅为了这个,试试'-std = gnu ++ 11',看看会发生什么。 – Casey

+0

工作正常!我也有#include vjktm

+0

我现在发现矢量有同样的问题。 vector <>很好-std = C++ 11 – vjktm

回答

6

比模式切换到-std=gnu++11大概少管闲事的解决办法是-U__STRICT_ANSI__。这将在stdio.h:234(GCC 4.8.3)中启用#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L)

+2

这可以在Cygwin上使用'-std = C++ 11'。 –

+0

当在ubuntu/linux和windows上用cygwin构建时,那么这个解决方案将是最好的解决方案 - 它为我工作 - 谢谢 – serup

相关问题