Write a C++ program reads the grades. Declare a variable of type ifstream which is used to input a stream from a file: ifstream input; // input is the name of the variable Use the input operator (>>) to read data from the above file: input >> score1 >> score2 << score3; //
C++ Program :
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
int score1,score2,score3; //to store values of score
string s;
cout<<"ENTER FILE NAME :"; //name for file
cin>>s;
ifstream input(s); //ifstream class for reading
while(input>>score1>>score2>>score3) //loop will iterate till file will not reach to eof
{
cout<<score1<<" "<<score2<<" "<<score3<<endl;
}
return 0;
}
file.txt content :
Output:
If you have any doubt feel free to ask and if you like the answer please upvote it .
Thanks
Get Answers For Free
Most questions answered within 1 hours.