fstream datoteka;
datoteka.open(\"Informacije.txt\", fstream::in | fstream::out | fstream::app);
if(!datoteka.is_open()){
ifstream datoteka(\"Inf
datoteka.open(filename, std::fstream::in | std::fstream::out | std::fstream::app);
works fine.
#include <fstream>
#include <iostream>
using namespace std;
int main(void)
{
char filename[ ] = "Informacije.txt";
fstream appendFileToWorkWith;
appendFileToWorkWith.open(filename, std::fstream::in | std::fstream::out | std::fstream::app);
// If file does not exist, Create new file
if (!appendFileToWorkWith )
{
cout << "Cannot open file, file does not exist. Creating new file..";
appendFileToWorkWith.open(filename, fstream::in | fstream::out | fstream::trunc);
appendFileToWorkWith <<"\n";
appendFileToWorkWith.close();
}
else
{ // use existing file
cout<<"success "<<filename <<" found. \n";
cout<<"\nAppending writing and working with existing file"<<"\n---\n";
appendFileToWorkWith << "Appending writing and working with existing file"<<"\n---\n";
appendFileToWorkWith.close();
cout<<"\n";
}
return 0;
}
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;
}