codice:
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <string>

using namespace std;

void scrivi(string, string);
string leggi(string);

int main()
{
    string test = "this.txt", txt = "ioioio%endioioio";
    scrivi(test, txt);
    cout << leggi(test) << endl;
    system("PAUSE");
    return 0;
}

void scrivi(string nome, string text)
{
    stringstream temp_write;
    ofstream out(nome.c_str());
    temp_write << text;
    text = temp_write.str();
    out << text << "%end" << text;
    out.close();
}

string leggi(string nome)
{
    string cosa, tmp;
    bool trovato = false;
    stringstream temp_read;
    ifstream in(nome.c_str());
    while(in)
    {
        temp_read << in;
    }
    while(temp_read)
    {
        if(temp_read.str() == "%end")
        {
            cosa = temp_read.str();
            trovato = true;
        }
        if(trovato)
        {
            cosa = tmp;
            continue;
        }
    }
    cosa = temp_read.str();
    return cosa.c_str();
}
Prova a dirmi cosa ti da............... a me nulla