I\'m using Visual C++ Express 2010... and I\'m very new to C++.
I want to read a file then remove everything before the word \"<--START-->\" and rewrite the file
std::string file_contents = LoadFileAsString("text.txt");
std::string::size_type offset = file_contents.find("<--START-->");
std::ofstream("text.txt") << file_contents.c_str() + offset;
With LoadFileAsString defined like this:
std::string LoadFileAsString(const std::string & fn)
{
std::ifstream fin(fn.c_str());
if(!fin)
{
std::string what = "LoadFileAsString() : Failed to open file \"";
what += fn + '\"';
throw std::runtime_error(what);
}
std::ostringstream oss;
oss << fin.rdbuf();
return oss.str();
}