Guest User

Untitled

a guest
Jan 19th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <fstream> // para usar file streams (ifstream,ofstream)
  2. #include <iostream> // para usar cin,cout
  3. #include <string> // para usar string
  4. #include <iomanip> // para usar manipuladores (setw, right, ...)
  5. #include <cstdlib> // para usar srand(), rand() e exit()
  6.  
  7. using namespace std;
  8. void leArquivo(string nomeArq);
  9.  
  10.  
  11. int main()
  12. {
  13. string leArquivo("contatos.txt");
  14.  
  15.  
  16.  
  17.  
  18. return 0;
  19. }
  20.  
  21. void leArquivo(string nomeArq)
  22. {
  23. // Cria input file stream (ifstream)
  24. ifstream arq;
  25.  
  26. cout << "Abrindo arquivo texto..." << endl;
  27.  
  28. // Abre arquivo
  29. arq.open( nomeArq.c_str() , ios::in );
  30.  
  31. // Se houver erro, sai do programa
  32. if (!arq.is_open())
  33. {
  34. cout << "Não foi possível abrir o arquivo!" << endl;
  35. exit(1);
  36. }
  37.  
  38. // Lê cabeçalho
  39. string aux;
  40. getline(arq, aux);
  41.  
  42. // Exibe cabeçalho na tela
  43. cout << aux << endl;
  44.  
  45.  
  46. arq.close();
  47. }
Add Comment
Please, Sign In to add comment