Skip to content

Instantly share code, notes, and snippets.

@shouc
Created November 26, 2019 18:29
Show Gist options
  • Save shouc/8f4f921ab968424c6894b741f76846c6 to your computer and use it in GitHub Desktop.
Save shouc/8f4f921ab968424c6894b741f76846c6 to your computer and use it in GitHub Desktop.
midterm-2
#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