atof funktion funktioniert nicht



  • Ich bin ein Anfänger und habe ein Buch (C++ Programmieren mit einfachen Beispielen)
    dort ist die atof() funktion wie im folgendem Quelltext beschrieben nur es funktioniertnicht. Vielleicht kann mir einer weiterhelfen arbeite mit Dev-C++ würde mich über jede hilfe freuen.

    #include <iostream>
    #include <string>
    #include <cstdio>
    using namespace std;

    int main(){
    for(double i = 1;i <= 100;i = i){

    double fahrenheit = 223456;
    string umgekehrt = "der wechselwert";
    for(double j = 1;j <= 100;j = j){

    cout << "Fahrenheit zu Celsius" << endl << endl;

    cout << "Geben Sie einen Wert in Fahrenheit ein oder 'u' f\x81\x72 umgekehrt: ";
    cin >> umgekehrt;
    if(umgekehrt != "u"){
    ⚠ fahrenheit = atof(umgekehrt.c_umgekehrt()); ⚠
    }
    cout << endl << endl;
    if(umgekehrt == "u"){
    cout << "Celsius zu Fahrenheit" << endl << endl;
    cout << "Geben Sie einen Wert in Grad Celsius ein oder 'u' f\x81\x72 umgekehrt: ";
    cin >> umgekehrt;
    if(umgekehrt != "u"){
    ⚠ fahrenheit = atof(umgekehrt.c_umgekehrt()); ⚠
    }
    if(umgekehrt == "u"){
    cout << endl << endl;
    }
    else{
    double zahl = fahrenheit * 9.0;
    zahl = zahl / 5;
    zahl = zahl + 32;
    cout << fahrenheit
    << " Grad Celsius entsprechen "
    << zahl
    << " Grad Fahrenheit" << endl << endl;
    break;
    }
    }
    else{

    double celsius = (fahrenheit - 32) * 5.0 / 9.0;

    cout << fahrenheit
    << " Grad Fahrenheit entsprechen "
    << celsius
    << " Grad Celsius" << endl << endl;
    break;
    }
    }

    cout << "Bitte 'ende' oder 'n' f\x81\x72 nochmal eingeben: ";
    string ende;
    cin >> ende;
    cout << endl << endl << endl;
    if(ende == "ende"){
    break;
    }
    if(ende == "Ende"){
    break;
    }
    }

    return 0;
    }



  • #include <iostream> 
    #include <string> 
    #include <cstdio> 
    using namespace std; 
    
    int main()
    { 
    	for(double i = 1;i <= 100;i = i)
    	{ 
    		double fahrenheit = 223456; 
    		string umgekehrt = "der wechselwert"; 
    
    		for(double j = 1;j <= 100;j = j)
    		{ 
    			cout << "Fahrenheit zu Celsius" << endl << endl; 
    			cout << "Geben Sie einen Wert in Fahrenheit ein oder 'u' f\x81\x72 umgekehrt: "; 
    
    			cin >> umgekehrt; 
    
    			if(umgekehrt != "u")
    			{ 
    				fahrenheit = atof(umgekehrt.c_str());  
    			} 
    
    			cout << endl << endl; 
    
    			if(umgekehrt == "u")
    			{ 
    				cout << "Celsius zu Fahrenheit" << endl << endl; 
    				cout << "Geben Sie einen Wert in Grad Celsius ein oder 'u' f\x81\x72 umgekehrt: "; 
    
    				cin >> umgekehrt; 
    
    				if(umgekehrt != "u")
    				{ 
    					fahrenheit = atof(umgekehrt.c_str());  
    				} 
    
    				if(umgekehrt == "u")
    				{ 
    					cout << endl << endl; 
    				} 
    				else
    				{ 
    					double zahl = fahrenheit * 9.0; 
    					zahl = zahl / 5; 
    					zahl = zahl + 32; 
    					cout << fahrenheit << " Grad Celsius entsprechen " << zahl << " Grad Fahrenheit" << endl << endl; 
    				} 
    			} 
    
    			else
    			{ 
    				double celsius = (fahrenheit - 32) * 5.0 / 9.0; 
    				cout << fahrenheit << " Grad Fahrenheit entsprechen " << celsius << " Grad Celsius" << endl << endl; 
    			} 
    		} 
    
    		cout << "Bitte 'ende' oder 'n' f\x81\x72 nochmal eingeben: "; 
    
    		string ende; 
    		cin >> ende; 
    
    		cout << endl << endl << endl; 
    } 
    
    return 0; 
    }
    

    !? Laut cppreference gibt es kein std::string::c_umgekehrt() 🤡



  • als Beispiel stand im Buch:

    string str = "123.456";
    double doubleZahl;

    doubleZahl = atof(str.c_str());
    cout << doubleZahl << endl; 😃 😃 😃



  • Ja, das sieht auch richtig aus. Du hattest in deinem Code nur ...c_umgekehrt() anstatt ...c_str() stehen.



  • die funktion c_str() gibt einen c string zurück
    und sie heisst genau so und nicht c_NAME-DES-STRINGS()

    einfach nur c_str()...

    ist aber unter umständen auch blöd mit dem namen in dem buch 😉



  • Also ich finds lustig. Das is doch mal ein geiler Fehler 😃


Anmelden zum Antworten