我試圖編譯使用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