C++ : Creating program that reads a text file -


i need new. text below has been created on separate file(football.txt). trying create program can read data , have displayed.

player name:    rusell william salaray:        $8000000 age:            20 team:           seahawks position:       quarterback 

this have,

//this program read text files display  #include <iostream> #include <fstream> #include <iomanip> #include <string> using namespace std;  int main() {  //declaring variables      int salary, age;     string firstname, lastname, team, position;  //delcaring file.      ifstream infile;     infile.open("football.txt", ios::in);      if (!infile) {   cout<<"file not exist"; }      infile.close();      ofstream outfile;  //declare on display      cout<<"**********player summary*********\n";     outfile.open("football.txt", ios::app);     outfile<<"football.txt";     outfile.close();     return 0; } 

no errors, no displayed neither.

try sample program , build on it:

#include <iostream> #include <fstream> #include <string>  using namespace std;  int main(void) {     ifstream infile;     infile.open("football.txt", ios::in);      if (!infile)     {        cout<<"file not exist";        return exit_failure;     }     std::string text_from file;     while (getline(infile, text_from_file))     {        cout << text_from_file << "\n";     }      cout << "paused. press enter continue.\n"     cin.ignore(10000, '\n');      return exit_success; } 

notice text being read file using getline function.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -