diff options
author | Oskar <[email protected]> | 2024-08-30 18:32:44 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-08-30 18:32:44 +0200 |
commit | 8f54ef4d7e1c112e6dde2947a6a9a27c8393f899 (patch) | |
tree | b03a37618329a3a00976028e702290596e2171d7 /5p16.cpp | |
parent | 2952047fe741ca5b3717e066e0a6aeac699ee4c1 (diff) |
more
Diffstat (limited to '5p16.cpp')
-rw-r--r-- | 5p16.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/5p16.cpp b/5p16.cpp new file mode 100644 index 0000000..27c6bcb --- /dev/null +++ b/5p16.cpp @@ -0,0 +1,57 @@ +#include <iostream> +#include <vector> + +/* + * + * 5.16 + * + * + */ + +void idiomatic_while(std::vector<int> &idw) { + + int i = 0; + while(std::cin >> i) { + idw.push_back(i); + } +} + +void idiomatic_for(std::vector<int> &idf) { + + for(auto a : idf) { + std::cout << a << std::endl; + } +} + +void nonidiomatic_while(std::vector<int> &nidw) { + + auto iter = nidw.cbegin(); + while(iter != nidw.cend()) { + std::cout << *iter++ << std::endl; + } +} + +void nonidiomatic_for(std::vector<int> &nidf) { + + int i = 0; + for( ; std::cin >> i ; ) { + nidf.push_back(i); + } +} + +int main (int argc, char *argv[]) { + + if(argc > 2 || argc < 2) { return -1; } + std::string argv_s = argv[1]; + std::vector<int> iv1; + std::vector<int> iv2; + if(argv_s == "1") { + idiomatic_while(iv1); + idiomatic_for(iv1); + } else if (argv_s == "2") { + nonidiomatic_for(iv2); + nonidiomatic_while(iv2); + } + + return 0; +} |