Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use snprintf() in g++ -std=c++11 version 4.8.2

I am trying compile code that uses snprintf in version 4.8.2 of g++ with -std=c++11 without success. Why doesn't g++ recognize snprintf? Can I overcome this while still using snprintf and c++11?

I got the following:

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 ****
like image 481
vjktm Avatar asked Nov 22 '13 16:11

vjktm


1 Answers

Probably less intrusive solution than switching the mode to -std=gnu++11 is -U__STRICT_ANSI__. This will enable #if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L) at stdio.h:234 (GCC 4.8.3).

like image 129
Pavel Kirienko Avatar answered Sep 28 '22 16:09

Pavel Kirienko