Palavras
C++
#include <iostream>
#include <fstream>
using namespace std;
void salva_arquivo() {
ofstream arquivoSaida;
arquivoSaida.open("palavras.txt");
arquivoSaida << "5 ABCAXI BANANA UVA MELANCIA MORANGO";
arquivoSaida.close();
}
void ler_arquivo() {
ifstream arquivo;
arquivo.open("palavras.txt");
int quantidade_palavras;
arquivo >> quantidade_palavras;
cout << "O arquivo possui " << quantidade_palavras << " palavras." << endl;
for (int i=0;i<quantidade_palavras;i++){
string palavra_lida;
arquivo >> palavra_lida;
cout << "Palavra " << i + 1 << ": " << palavra_lida << endl;
}
}
int main() {
salva_arquivo();
ler_arquivo();
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.