how can input 5 datas in a file an then output all tthem.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abdulazizi
    New Member
    • Jan 2012
    • 2

    #1

    how can input 5 datas in a file an then output all tthem.

    #include <iostream>
    #include <fstream>
    #include <string>

    using namespace std;

    // this program contains an error

    int main()
    {
    ifstream ifs("data.txt") ;
    string name;
    cout<<"enter the names:"<<endl;
    for(int i=0;i<6;i++)
    {
    cin>>name;
    }
    // error in stream test
    while(!ifs.eof( ))
    {
    cout<<name<< endl;
    }

    system ("pause");
    return 0;
    }
  • abdulazizi
    New Member
    • Jan 2012
    • 2

    #2
    while(!ifs.eof( ))
    {
    cout<<name<< endl;
    }
    this is the problem, it reads through the file non stop

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      You never read the file.

      Comment

      Working...