Cannot Open File

I am doing a program to change the parameter file. Here I have to read a text file. Search for appropriate parameter and replace it. The modified parameter contains and unchanged are kept in buffer. Now i have to write this data in same file i using to read. I face problem while writing buffer data to file. It throws file can't open exception.

OEUpdater::OEUpdater(const std::string& fileName)
{
src.exceptions ( ifstream::failbit | ifstream::badbit );
src.open(fileName.c_str(),ios_base::in);
FileName = fileName;
}

// look for key and update it's value . if key not found then add it with value.
void OEUpdater::update(const std::string& key, const std::string& value)
{
std::string replace = key + ": " + value + "\n";
std::string cur_line;
std::string file_content ;
bool found = false;

// key value search and replace part //

src.close();
// reopen file with truncation
fstream tgt;

// This part is throwing exception //

tgt.exceptions ( ifstream::failbit | ifstream::badbit );
tgt.open(FileName.c_str(), ios::trunc);
// add the content.
tgt << file_content;
tgt.close();
}
Next time, please use code tags (check the format table).

Anyway:
tgt.open(FileName.c_str(), ios::trunc);
Shouldn't that be ios_base::trunc (or fstream::trunc)?
Topic archived. No new replies allowed.