How can i get to read a .txt file that has a list of names and ages. Example Angel 76, Joe 67, Paul 71. | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 2

How can i get to read a .txt file that has a list of names and ages. Example Angel 76, Joe 67, Paul 71.

I'm trying to learn at my 76 years how to program little stuff. any help will be grateful

31st Aug 2017, 4:06 AM
Angel Cosme
Angel Cosme - avatar
1 Réponse
+ 1
#include <iostream> #include <fstream> #include <string> using namespace std; void main () { string STRING; ifstream infile; infile.open ("names.txt"); while(!infile.eof) // To get you all the lines. { getline(infile,STRING); // Saves the line in STRING. cout<<STRING; // Prints our STRING. } infile.close(); system ("pause"); }
27th Sep 2017, 12:29 AM
Jeff Shipton
Jeff Shipton - avatar