Created
November 26, 2019 18:29
-
-
Save shouc/8f4f921ab968424c6894b741f76846c6 to your computer and use it in GitHub Desktop.
midterm-2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <fstream> | |
using namespace std; | |
int main(int argc, char const *argv[]) | |
{ | |
if (argc == 1){ | |
cerr << "Usage: ./" << argv[0] << " filename" << endl; | |
exit(1); | |
} | |
ifstream in; | |
string currentLine; | |
in.open(argv[1]); | |
if (!in){ | |
cerr << "Error opening file." << endl; | |
exit(1); | |
} | |
int counter = 1; | |
while (1){ | |
getline(in, currentLine); | |
if (!in){ | |
in.close(); | |
return 1; | |
} | |
cout << counter << ": " << currentLine << endl; | |
counter++; | |
} | |
in.close(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment