Created
May 2, 2010 01:58
-
-
Save zachelko/386826 to your computer and use it in GitHub Desktop.
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 <fstream> | |
#include <stdlib.h> | |
#include <string> | |
using namespace std; | |
int main(const int argc, const char* argv[]) | |
{ | |
if (argc != 2) | |
{ | |
cerr << "Usage: ./sumFromFile fileName\n"; | |
exit(1); | |
} | |
ifstream inStream(argv[1]); | |
string line; | |
int sum = 0; | |
while (getline(inStream, line)) | |
{ | |
sum += atoi(line.c_str()); | |
} | |
cerr << "Sum: " << sum << endl; | |
inStream.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment