I'm not understanding why i'm able to read from the file but i can't write to it. The fstream is open in both modes. Once the program finishes i haven't changed the content of the file.
Thank you in advance.
#include <fstream>
#include <string>
#include <iostream>
int main()
{
std::string line;
std::fstream m_File("/home/user/file.txt", std::ios::in | std::ios::out);
if(m_File.fail())
return -1;
// read file
std::getline(m_File, line);
while(m_File.good())
{
std::getline(m_File, line);
std::cout << line << std::endl;
}
// write to file
std::string line2 = "test to write";
m_File.seekp(std::ios_base::beg);
m_File << line2;
m_File.close();
return 0;
}