Home » C++ String swap() function

C++ String swap() function

by Online Tutorials Library

C++ String swap()

This function is used to exchange the values of two string objects.

Syntax

Consider two strings s1 and s2 , we want to exchange the values of these two string objects. Its syntax would be :

Parameters

It contains single parameter, whose value is to be exchanged with that of the string object.

Return value

It does not return any value.

Example 1

Output:

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.

Next TopicC++ Strings

You may also like