Created
October 4, 2022 03:22
-
-
Save mshafae/83a91cafc678eaf64db6f3ac7d6e5438 to your computer and use it in GitHub Desktop.
Sum all integers provided on the command line.
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
// 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