If file exist, work with it, if no, create it

后端 未结 2 1661
独厮守ぢ
独厮守ぢ 2021-01-05 09:23
fstream datoteka;
datoteka.open(\"Informacije.txt\",  fstream::in | fstream::out | fstream::app);

if(!datoteka.is_open()){              
    ifstream datoteka(\"Inf         


        
2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-05 09:46

    If filename does not exist, the file is created. Otherwise, the fstream::app, If file filename already exists, append the data to the file instead of overwriting it.

    int writeOnfile (char* filetext) {
           ofstream myfile;
           myfile.open ("checkSellExit_file_output.csv", fstream::app);
           myfile << filetext;
           myfile.close();
           return 0;
        }
    

提交回复
热议问题