/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <string>
#include <fstream>
#include <streambuf>
#include <sstream> //std::stringstream
#include <boost/algorithm/string/replace.hpp>
using namespace std;
int main()
{
// CRIO O ARQUIVO
std::ofstream outfile ("test.txt");
outfile << "conteudo do arquivo!" << std::endl;
outfile.close();
//FIM DA CRIACAO DO ARQUIVO
//ABRE ARQUIVO
std::ifstream inFile;
inFile.open("test.txt"); //open the input file
std::stringstream strStream;
strStream << inFile.rdbuf(); //read the file
std::string str = strStream.str(); //str holds the content of the file
std::cout << str; //you can do anything with the string!!!
std::string s = str;
boost::replace_all(s, "arquivo", "ficha"); // REPLACE -> SUBSTITUI
//std::replace( s.begin(), s.end(), 'arquivo', 'ficha'); // replace all 'x' to 'y'
std::cout << s;
// CRIO O ARQUIVO MODIFICADO
std::ofstream outfile2 ("test2.txt");
outfile2 << s << std::endl;
outfile2.close();
//FIM DA CRIACAO DO ARQUIVO
return 0;
}
conteudo do arquivo!
aish
conteudo do ficha!