C++ String swap()
This function is used to exchange the values of two string objects.
Consider two strings s1 and s2 , we want to exchange the values of these two string objects. Its syntax would be :
It contains single parameter, whose value is to be exchanged with that of the string object.
It does not return any value.
Before swap r contains 10 rupees Before swap m contains 20 rupees After swap r contains 20 rupees After swap m contains 10 rupees
In this example, r and m are two string objects containing 10 and 20 rupees respectively. We swap there values by using swap function. After swapping, r contains 20 rupees and m contains 10 rupees.