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;
- // varibles for our libary
- int main()
- {
- //varibles for code
- ifstream inputFile;
- string filename, name, clas, gpa, read;
- int count=0;
- // getting our the fille name.
- cout << "Enter the file name (name.txt)" << endl;
- cin >> filename; // putting the stars when each part starts
- cout << "**********" << endl;
- inputFile.open(filename);
- // if statement if the file is open
- // using read to read the data
- while (inputFile >> read)
- {
- // count diffrent info each time to the next set of info
- count=count + 1;
- // couting the Name
- if (read=="Name:"){
- inputFile >> name;
- }
- else if (read=="Class:"){
- inputFile >> clas;
- }
- else if (read=="GPA:"){
- inputFile >> gpa;
- }
- // for each 3 sets of info it realizes that it needs to print the info
- if (count == 3) {
- cout << " Name: " << name << endl;
- cout << " Class: " << clas << endl;
- cout << " Gpa " << gpa << endl;
- cout << " ******** " << endl;
- count = 0;
- // reseting the loop
- }
- }// ends function
- //putting the stars after the 3 part is finsihed
- inputFile.close();
- // close file
- return 0;
- }// end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement