Seite 1 von 1

std::sprintf, std::strlen .. Windows(VS) % Ubuntu(gcc) ..

Verfasst: 23.05.2012, 21:08
von HeinzK
Eine Frage: Warum gibt es z.Bsp. 'std::sprintf' oder 'std::strlen' nicht unter Ubuntu(gcc)? Ist die STL nicht auf allen Plattformen identisch?
Oder liegt das an meiner gcc-Version?

Re: std::sprintf, std::strlen .. Windows(VS) % Ubuntu(gcc) .

Verfasst: 23.05.2012, 21:35
von Biolunar
Hast du <cstdio> und <cstring> includiert?

Re: std::sprintf, std::strlen .. Windows(VS) % Ubuntu(gcc) .

Verfasst: 23.05.2012, 21:45
von HeinzK
Nein, nur ..

Code: Alles auswählen

#include <stdio.h>
#include <limits.h>
#include <string>
#include <sstream>
.. aber z.Bsp. 'std::max' ist auf beiden Plattformen vorhanden.

Re: std::sprintf, std::strlen .. Windows(VS) % Ubuntu(gcc) .

Verfasst: 23.05.2012, 22:57
von dot
std::max kommt aus <algorithm>. Viele Standardheader inkludieren abhängig von der jeweiligen Implementierung implizit schon einige andere Header mit. Darauf kannst du dich aber nicht verlassen. Daher: <cstdio> und <cstring> inkludieren.

Btw: stdio.h und limits.h sind keine C++ Standardheader ;)

Re: std::sprintf, std::strlen .. Windows(VS) % Ubuntu(gcc) .

Verfasst: 24.05.2012, 08:57
von HeinzK
Ich habe mal alle 'includes' durch ihre 'c'-Version ersetzt .. <ccomplex> macht aber unter Ubuntu(gcc) Probleme.

Code: Alles auswählen

-------------- Build: Debug in Test ---------------
Compiling: ../../../_KBasis/Basis/KArchive.cpp
In file included from /usr/include/c++/4.4/ccomplex:35,
                 from /media/C_DRIVE/Kempter/VC10/_SFML/_ZwiAnerPrj/Tests/stdafx.h:49,
                 from /media/C_DRIVE/Kempter/VC10/_KBasis/Basis/KArchive.cpp:1:
/usr/include/c++/4.4/c++0x_warning.h:31:2: error: #error This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.
Process terminated with status 1 (0 minutes, 1 seconds)
1 errors, 0 warnings (0 minutes, 1 seconds)
/usr/include/c++/4.4/ccomplex:35
Ist mein gcc (wx2.8.10) nicht aktuell genug?
PS: Aktueller Stand meiner 'includes':

Code: Alles auswählen

//#include <stdlib.h>
#include <cstdlib>
//#include <stdarg.h>
#include <cstdarg>
//#include <stdio.h>
#include <cstdio>
//#include <string>
#include <cstring>
//#include <limits.h>
#include <climits>
//#include <math.h>
#include <cmath>
#ifdef _WIN32
  #include <ccomplex>
#else  
  #include <complex>
#endif
//#include <float.h>
#include <cfloat>
#include <memory.h>
#include <malloc.h>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <map>
Spielt die Reihenfolge eine Rolle?

Re: std::sprintf, std::strlen .. Windows(VS) % Ubuntu(gcc) .

Verfasst: 24.05.2012, 09:13
von Florian Keßeler
Da steht doch, was das Problem ist. Du musst C++11-Support einschalten, in dem du -std=c++0x bei deinen Compilerflags mit angibst.

Re: std::sprintf, std::strlen .. Windows(VS) % Ubuntu(gcc) .

Verfasst: 24.05.2012, 09:26
von HeinzK
Danke für den Hinweis .. ich bin unter Ubuntu(gcc) noch etwas auf Glatteis. Mit -std=gnu++0x hat es dann geklappt.
Hurra .. nun bin ich experimentell! 8-) (zumindest in der Linuxwelt)

Re: std::sprintf, std::strlen .. Windows(VS) % Ubuntu(gcc) .

Verfasst: 24.05.2012, 09:42
von Florian Keßeler
Unter Visual Studio hast du auch experimentellen C++0x support aktiv, nur dass du ihn meines Wissens nach nicht extra einschalten musst...

Re: std::sprintf, std::strlen .. Windows(VS) % Ubuntu(gcc) .

Verfasst: 24.05.2012, 09:48
von HeinzK
Einen sichtbaren Schalter dazu sehe ich nicht ..

Re: std::sprintf, std::strlen .. Windows(VS) % Ubuntu(gcc) .

Verfasst: 24.05.2012, 11:04
von Schrompf
Bei Visual Studio ist der Schalter unsichtbar: ab VS10 hast Du automatisch das Bisschen an C++11, was der Compiler kann.