Skip to content

Instantly share code, notes, and snippets.

@zachelko
Created May 2, 2010 01:58
Show Gist options
  • Save zachelko/386826 to your computer and use it in GitHub Desktop.
Save zachelko/386826 to your computer and use it in GitHub Desktop.
#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