1: //TestStuff20140910.cpp 2: //Monday, September 10, 2014 3: 4: //Note: This file uses the file lines.txt. 5: 6: #include <iostream> //this is where cout, endl and cin.ignore() live 7: #include <fstream> //this is where ifstream lives 8: #include <string> //this is where getline() and to_string() live 9: #include <cstdlib> //this is where atoi() lives 10: using namespace std; 11: 12: int main(int argc, char* argv[]) 13: { 14: if (argc == 1) //Remember: there is always at least one 15: { //command-line parameter (the name of the program) 16: cout << "\nLastname:Firstname:A00123456:csc34101" 17: "\nSubmission 01: Finding Augusts with Five Weekends"; 18: 19: cout << "\n\nThis program analyzes an input file of calendar data " 20: "to determine which\nyears in a range of years between 2000 and " 21: "3000 (inclusive)contain a month\nof August which has five " 22: "complete weekends (Friday, Saturday, and Sunday).\n"; 23: cout << "Press Enter to continue ... "; cin.ignore(80, '\n'); 24: return EXIT_SUCCESS; //A built in constant 25: } 26: 27: cout << "\nJust carrying on ..." << endl; 28: //The above statement will be executed if there are any 29: //command-line parameters 30: 31: //This should be used so that the first command-line parameter 32: //(the name of the file) is opened for input as inFile 33: ifstream inFile(argv[1]); 34: 35: //Do *not* hard-wire the file name into your code like this ... 36: //ifstream inFile("lines.txt"); 37: 38: //The following code opens a file reads all the lines in it, 39: //and reports the location of the first occurrence of the 40: //word "line". 41: //string line; 42: //while (getline(inFile, line)) 43: //{ 44: // string::size_type position = line.find("line"); 45: // if (position != string::npos) 46: // cout << "\"line\" found at index " << position << ".\n"; 47: // else 48: // cout << "\"line\" not found on this line." << endl; 49: // //cout << line << endl; 50: //} 51: 52: //string s = "Hello"; 53: //The at() member function in the string class interface returns 54: //character at a given index location (0 is the first index) 55: //cout << s.at(1) << endl; 56: 57: //Illustrates an integer array ... 58: //int years[1000]; 59: //years[0] = 2017; 60: //years[1] = 2154; 61: //years[2] = 2345; 62: //for (int i = 0; i < 3; i++) 63: //{ 64: // cout << years[i] << endl; 65: //} 66: 67: //Illustrates how to turn an integer into a string ... 68: //int someYear = 2345; 69: //string someYearAsAString = to_string(someYear); 70: //cout << someYearAsAString.at(2) << endl; 71: 72: //Illustrates how to turn a comand-line parameter which contains 73: //nothing but digits into the corresponding integer (int value) 74: char numberString[] = "1234"; 75: string numberString2 = "1234"; //not the same at all 76: int year = atoi(numberString); 77: ++year; 78: cout << year << endl; 79: }