summaryrefslogtreecommitdiff
path: root/strings-tests.cpp
blob: 7cce52eb247502b8dd806f4c8cc4ddefd6bf7e0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#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;
}