Created
March 8, 2017 20:23
-
-
Save Adals20/f016e78427e8ad891931157236efb1f5 to your computer and use it in GitHub Desktop.
This file contains 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 <iostream> | |
#include <fstream> | |
#include <string> | |
using namespace std; | |
int main (){ | |
int palabras=0, lineas=0; | |
const string nfichero = "texto.txt"; | |
string cadena; | |
ifstream fichero; | |
fichero.open(nfichero.c_str()); | |
if(!fichero.fail()){ | |
getline(fichero, cadena); | |
//contador += cadena.length(); | |
while(!fichero.eof()){ | |
lineas++; | |
//cout << cadena << endl; | |
palabras += cadena.length(); | |
//cout << palabras << endl; | |
getline(fichero, cadena); | |
} | |
/*const string nfichero = "texto.txt"; | |
char cadena [80]; | |
ifstream fichero; | |
fichero.open(nfichero.c_str()); | |
if(!fichero.fail()){ | |
fichero.getline(cadena, 80, '\n'); | |
while(!fichero.eof()){ | |
//cout << cadena << endl; | |
fichero.getline(cadena, 80, '\n'); | |
contador1++; | |
} | |
*/fichero.close(); | |
cout << "El numero de caracteres es: "<< palabras << endl; | |
cout << "El numero de lineas es: "<< lineas; | |
//} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment