Created
June 13, 2018 07:09
-
-
Save junquera/e060bf993a0c90f115c39b9cf986db56 to your computer and use it in GitHub Desktop.
Breve resumen de funciones básicas de IO para C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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