C++: Copy a String

Bjarne-stroustrup
 

This task is about copying a string. Where it is relevant, distinguish between copying the contents of a string versus making an additional reference to an existing string.

#include <iostream>
#include <string>

int main( ) {
	std::string original ("This is the original");
	std::string my_copy = original;
	std::cout << "This is the copy: " << my_copy << std::endl;
	original = "Now we change the original! ";
	std::cout << "my_copy still is " << my_copy << std::endl;
}

SOURCE

Content is available under GNU Free Documentation License 1.2.