wird sprintf(...) noch genutzt?



  • HALLO.

    noch eine weitere anfängerfrage zu folgendem funktionierenden code:

    #include <conio.h>
    #include <iostream>
    #include <cmath>
    #include <fstream>
    #include <sstream>
    
    using namespace std;
    
    int main()
    {
    	double a;
    	std::stringstream filename;
    	char buf[30];
    
            a = sqrt(4.0);
    	filename << "datei" << a << ".txt";
    	sprintf(buf, filename.str().c_str());
    	std::ofstream myfile( buf, std::ios_base::out | std::ios_base::app );
    	myfile.close();
    
        return 0;
    }
    

    mein compiler gibt mir hier eine warnung, das sprintf schon veraltet ist. wie macht man den das dann "heutzutage"?



  • Du kannst filename.str().c_str() direkt an den ofstream Konstruktor geben.



  • cool!
    vielen dank!


Anmelden zum Antworten