Skip to content

Instantly share code, notes, and snippets.

@junquera
Created June 13, 2018 07:09
Show Gist options
  • Select an option

  • Save junquera/e060bf993a0c90f115c39b9cf986db56 to your computer and use it in GitHub Desktop.

Select an option

Save junquera/e060bf993a0c90f115c39b9cf986db56 to your computer and use it in GitHub Desktop.
Breve resumen de funciones básicas de IO para C++
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
void escribe(string fichero, string contenido);
string lee(string fichero);
main() {
string fichero;
string miNombre;
cout << "Mi nombre es: " << endl;
cin >> miNombre;
cout << "El fichero es: " << endl;
cin >> fichero;
escribe(fichero, miNombre);
cout << lee(fichero) << endl;
}
void escribe(string fichero, string contenido){
ofstream archivoTexto;
archivoTexto.open(fichero);
archivoTexto << contenido << endl;
archivoTexto.close();
}
string lee(string fichero){
ifstream archivoTexto;
archivoTexto.open(fichero);
string res;
string leido;
while(getline(archivoTexto, leido)){
res += leido;
continue;
}
archivoTexto.close();
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment