Need explaination with string find

Hi, can anyone care to explain to me how the following code work? I got a code to basically to remove duplicate character but I do not understand how it work. Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23


                string str1 = "testing";
		string str2;
		int pos;
		
	for (int i = 0; i < str1.length(); i++)
	{
		
		if( (pos = str2.find(str1[i])) < 0)
			
				
			
			str2+= str1[i];
			
		
	}







I'll tell you the general algorithm. You can figure out how the code implements it.

Walk each character in the source string. If the character has already been added to the destination string,
then don't add it a second time, otherwise add it to the second string.
Also to understand this you need to know that a "string" is a class that is literally an array of characters, see here: http://www.cplusplus.com/reference/string/string/string/. These are the constructors for that class.

Thanks for the reply! Am I right to say if the char had not been added before pos will be 0?
Topic archived. No new replies allowed.