Skip to content

Instantly share code, notes, and snippets.

@Adals20
Created March 8, 2017 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Adals20/f016e78427e8ad891931157236efb1f5 to your computer and use it in GitHub Desktop.
Save Adals20/f016e78427e8ad891931157236efb1f5 to your computer and use it in GitHub Desktop.
#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