0

Using wfstream i am trying to write some processed content removing the old contents from file.

wfstream cSrcFileOutput(m_cstrFile);
wfstream cSrcFileInput(m_cstrFile);
std::wstring cstrSrcFileContent;
....

cstrSrcFileContent has my content

I am writing as below :

cSrcFileOutput.write(cstrSrcFileContent.c_str(), cstrSrcFileContent.size()*sizeof(wchar_t));

The problem is it's not clearing the previous data. instead it's inserting processed content somewhere in the file.

I want the old content replaced with the new processed content.

Please suggest.

sohel14_cse_ju
  • 2,481
  • 9
  • 34
  • 55
  • 1
    Possible duplicate of [clear data inside text file in c++](http://stackoverflow.com/questions/17032970/clear-data-inside-text-file-in-c) – Andrew Truckle May 17 '16 at 10:22

1 Answers1

0

When you open the file, you set the mode for how the data should be written to the file through the second parameter to the constructor

std::wfstream cSrcFileOutput(m_cstrFile, std::wfstream::out | std::wfstream::trunc);

where std::wfstream::trunc means overwrite existing contents (see std::basic_fstream::basic_fstream for constructor documentation).

IInspectable
  • 46,945
  • 8
  • 85
  • 181