Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication7.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <sstream>
- #include <stdlib.h>
- using namespace std;
- int main()
- {
- ifstream infile;
- string line; // one line of text
- string token;
- int token_count = 0;
- int hw_total = 0;
- infile.open("140-grades-1 asdf.txt");
- if (!infile) {
- cout << "Could not open file to read. Exiting program" << endl;
- return -1;
- }
- while (!infile.eof()) { //I don't understand what's !infile.eof(), look it up later
- getline(infile, line);
- if (line[0] == '/') { //if the position 0 has '/' skip the line such as the first line in the text file
- // it's a comment line, skip
- continue;
- }
- //DEBUG: cout << "line: " << line << endl;
- stringstream ss(line); // turn line of text into a stream.... ehh still don't get what's ss(line)
- while (getline(ss, token, ' ')) { //@_@ soo... ss would be the name??? OK I don't get the this part ss, token, ' '
- // cout << "tok: " << token << endl;
- switch (token_count)
- {
- case 0:
- cout << "Name: " << token;
- break;
- case 1:
- case 2:
- cout << "; HW: " << token;
- hw_total += stoi(token);
- }
- token_count++;
- }
- cout << "; Total: " << hw_total << endl;
- token_count = 0;
- hw_total = 0;
- }
- infile.close();
- cout << "done!" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment