2013-11-22 12 views
5

gprintの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

今、ベクトルに同じ問題があることがわかりました。ベクトル<>は-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とcygwinを使用したWindowsの両方でビルドする場合、このソリューションが最適なソリューションになります。 – serup

関連する問題