custom operator / in my string

Hi there! I have a question, how I can do operator / correctly. Operator / its like * but reversed. Operator * works like this - if it finds the same character, it saves it. In operator / I have to implement the condition, if I do not find the same character in the second I save a character in res, that is not found in the second
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
String operator*(String kek) {   //Operator '*'
		String res = "";

		for (int i = 0; i < size; i++) {
			for (int j = 0; j < kek.size; j++) {
				if (this->str[i] == kek.str[j]) {
					res += kek.str[j];
				}
			}
		}
		return res;
	}
	String operator/(String kek) {   //Operator '/' 
		String res = "";
		for (int i = 0; i < size; i++) {
			for (int j = 0; j < kek.size; j++) {
				if (this->str[i] != kek.str[j]) {
					res += str[i];
				}
			}
		}
		return res;
	}
Last edited on
You need to use bool:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
}
	String operator/(String kek) {   //Operator '/' 
		String res = "";
		for (int i = 0; i < size; i++) {
bool is_found = false;
			for (int j = 0; j < kek.size; j++) {
is_found = (this->str[i] == kek.str[j])
if(is_found)
  break;
			}
if(! is_found)
  res += str[i];
		}
		return res;
	}
Topic archived. No new replies allowed.