Skip to content

Instantly share code, notes, and snippets.

@mshafae
Created October 4, 2022 03:22
Show Gist options
  • Save mshafae/83a91cafc678eaf64db6f3ac7d6e5438 to your computer and use it in GitHub Desktop.
Save mshafae/83a91cafc678eaf64db6f3ac7d6e5438 to your computer and use it in GitHub Desktop.
Sum all integers provided on the command line.
// Gist https://gist.github.com/83a91cafc678eaf64db6f3ac7d6e5438
#include <iostream>
#include <string>
#include <vector>
int main(int argc, char const *argv[]) {
std::vector<std::string> arguments =
std::vector<std::string>{argv, argv + argc};
int sum{0};
for (int i = 1; i < arguments.size(); i++) {
sum += stoi(arguments.at(i));
}
std::cout << sum << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment