Write a file in a specific path in C++

后端 未结 7 777
無奈伤痛
無奈伤痛 2020-11-30 10:29

I have this code that writes successfully a file:

    ofstream outfile (path);
    outfile.write(buffer,size);
    outfile.flush();
    outfile.close();
         


        
7条回答
  •  暖寄归人
    2020-11-30 10:51

    Try this:

    ofstream outfile;
    string createFile = "";    
    string path="/FULL_PATH";
    
    createFile = path.as() + "/" + "SAMPLE_FILENAME" + ".txt";          
    outfile.open(createFile.c_str());       
    outfile.close();
    
    //It works like a charm.
    

提交回复
热议问题