Modernes C++ programmieren

Okt 23, 2024

lst-0885-godb.cpp

//#(compile) c++; compiler:g132; options:-O3 -std=c++23; libs:-
// https://godbolt.org/z/1EMox3hW5 
#include <sstream>  // istringstream
#include <iostream>
int main() {
    std::istringstream istr;
    std::string sval("3.1415 : 4321");
    std::string none;
    double dval=0.0;
    int ival=0;
    istr.str(sval);                // initialisieren
    istr >> dval >> none >> ival;  // auslesen
    if( ! istr.eof() ) {
        std::cout << "Fehler beim Konvertieren\n"; return 1;
    }
    std::cout << dval << " == " << none << " == " << ival << "\n";
    // Ausgabe: 3.1415 == : == 4321
}