SurveyVisual
SurveyVisual

Reputation: 27

C++ Can't write file with peek ; using fstream

I create in C++ a function that write in file, by using stream. I want that file was overwrite when i call this code. When i add a fstream.peak, to know the next char, nothing was written in my text file. If they return -1, I want they write at X position in my text file. Here's my code (note that I begin in C++..) Thanks for the future help! :)

fstream myFStream = myFStream.open("./myFile.txt,  ios::in |ios::out | ios::trunc | ios::binary);
int positionFile = 2;
myFStream.seekp(positionFile, ios::beg);
char textToWrite[10] = "";
textToWrite = "mytext";

**// [don't write when I add this IF]
if (myFStream.peek() > 0) 
    { positionFile += 15; }**

 myFStream.write(textToWrite, 6);
 myFStream.close();

Upvotes: 0

Views: 369

Answers (0)

Related Questions