Umwandeln: String -> Double funktioniert nicht (CodeBlocks)



  • Hallo Zusammen,

    Ich versuche mir gerade C++ beizubringen und bin auf ein Problem gestoßen.

    Folgender Code:

    [code]
    #include <string>
    #include <iostream>
    using namespace std;
    
    int main() {
    
      // string -> double
    
        string const s = "0.5";
        double d = stod(s);
        cout << d << endl;
    
    }
    

    lässt sich mit MS Visual Studio 2013 compilern jedoch bei Code::Blocks wird mir der folgende Fehler gebracht.

    D:\cpp\cpp_projekt\Projekt1\main.cpp|11|error: 'stod' was not declared in this scope|

    Woran liegt das? Bzw. was muss ich bei Code::Blocks Umstellen, damit das funktioniert.


  • Mod

    Nichts kannst du da umgestalten. std::stod wird von MinGW eben (noch) nicht unterstützt.



  • #include <sstream>
    #include <string>
    #include <iostream>
    using namespace std;
    
    int main()
    {  
        string AlsString("3.14");
        stringstream Str;
        Str << AlsString;
        double d;
        Str >> d;
        cout << d << endl;
    }
    

    Also dann besser diese Variante hier verwenden?

    Danke für die Hilfe. Ich wäre schon fast an dem Problem verzweifelt.



  • Arcoth schrieb:

    Nichts kannst du da umgestalten. std::stod wird von MinGW eben (noch) nicht unterstützt.

    MinGW G++ ab Version 4.8.2 unterstützt stod.
    Also: neueren Compiler verwenden (Versionstest mit g++ --version)


Anmelden zum Antworten