Operator += applied a to a string value

I was going through this code I found on the c++ website and I haven't been able to figure out why the += works with string and char characters. Would anyone be able to explain how += works on a string? (Line 6 in the code)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// string::clear
#include <iostream>
#include <string>

int main ()
 {
1  char c;
2  std::string str;
3  std::cout << "Please type some lines of text. Enter a dot (.) to finish:\n";
4  do {
5    c = std::cin.get();
6    str += c;
7    if (c=='\n')
8    {
9       std::cout << str;
10       str.clear();
11   }
12  } while (c!='.');
13  return 0;
14}
It appends the character to the string.

1
2
3
std::string str = "Car";
str += 's';
std::cout << str; // prints "Cars" 
I haven't been able to figure out why the += works

Because std::string overloads operator+=:
http://en.cppreference.com/w/cpp/string/basic_string/operator%2B%3D
Ahhh okay it's overloaded, got it, thanks for the links guys.
Topic archived. No new replies allowed.