lerArquivo
C++
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ofstream arquivoSaida;
arquivoSaida.open("cursos.txt");
arquivoSaida << "3\n";
arquivoSaida << "PHP Curso\n";
arquivoSaida << "C++ Curso\n";
arquivoSaida << "Python Curso\n";
arquivoSaida.close();
ifstream arquivoEntrada;
string linha;
arquivoEntrada.open("cursos.txt");
if(arquivoEntrada.is_open()){
int qtd_cursos;
arquivoEntrada >> qtd_cursos;
cout << "total de cursos: " << qtd_cursos << endl;
while(getline(arquivoEntrada, linha)){
cout << linha << endl;
}
} else {
cout << "Não foi possivel abrir o arquivo" << endl;
}
return 0;
}
Output
Embed on website
To embed this program on your website, copy the following code and paste it into your website's HTML:
Comments
This comment belongs to a banned user and is only visible to admins.
This comment belongs to a deleted user and is only visible to admins.