Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <stdio.h>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- // filestream variable file
- fstream file;
- string Name, clas, gpa, filename;
- int count=0;
- // filename of the file
- cout << "Enter the file name (file.txt)" << endl;
- cin >> filename; // putting the stars when each part starts
- cout << "**********" << endl;
- // opening file
- file.open(filename);
- if(file){
- // extracting words form the file
- while (file >> Name)
- {
- // displaying content
- count=count + 1;
- // couting the Name,Class,and GPA
- if (Name=="Name:"){
- cout << Name << endl;
- }
- }
- // trying to separate the class
- while (file >> clas)
- {
- count=count + 1;
- if (clas=="Class:"){
- cout << clas << endl;
- }
- }
- // trying to separate the gpa
- while (file >> gpa)
- {
- count= count + 1;
- if (gpa=="GPA:"){
- cout << gpa << endl;
- }
- }
- }
- // else statement for the infile if statement
- else
- {
- cout << "Error";
- //error if file is not open
- }
- // ending with asterisks
- if (count>5){
- count=0;
- cout << "**********" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement