From 1d105b91b9678ffaa8eddea2218ed1789f5be27c Mon Sep 17 00:00:00 2001 From: Oskar Date: Sat, 3 Aug 2024 22:51:15 +0200 Subject: more assignments --- strings-tests.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 strings-tests.cpp (limited to 'strings-tests.cpp') diff --git a/strings-tests.cpp b/strings-tests.cpp new file mode 100644 index 0000000..7cce52e --- /dev/null +++ b/strings-tests.cpp @@ -0,0 +1,56 @@ +#include +#include "sales_data.hpp" +#include "sales_item.hpp" + +/* + * + * Description + * + * + */ + +using std::string; +using std::cout; +using std::cin; +using std::cerr; +using std::clog; +using std::endl; +int main () { + + string s1; // default initialization + string s2 = s1; // s2 copy from s1 + string s3 = "Hello, World!"; // initialize by copying string literal + string s4(10, 'a'); // initialize with n copies of a + string s5 = s3 + s4; // Initialize with s3+s4. Both are combined and copied to s5? + string s6("Hello, World! (s6)"); // Initialize by copying string literal + string s7(s3); // s7 is a copy of s3 + cout << s1 << endl; + cout << s2 << endl; + cout << s3 << endl; + cout << s4 << endl; + cout << s5 << endl; + cout << s6 << endl; + cout << s7 << endl; + + int choice = 0; + cin >> choice; + if(choice == 1) { + string input; + while(cin >> input) { cout << input << " "; } + + } else if (choice == 2) { + string word; + string::size_type total_len = 0; + while(getline(cin, word)) { + if(!word.empty()) { + total_len += word.size(); + cout << word << endl; + } + } + cout << "Total output amount of characters: " << total_len << endl; + } else { + return -1; + } + + return 0; +} -- cgit v1.2.3