Swapping strings - C++ STL

C++ examples for STL:string

Description

Swapping strings

Demo Code

#include <iostream>
#include <string>

int main(int argc, const char* argv[]) {
    std::string first("one");
    std::string second("two");

    std::cout << "Before swap:\n first: " << first << "\nsecond: " << second;

    first.swap(second);//  w w  w  .  j  a v  a2  s.c om

    std::cout << "\n\nAfter swap:\n first: " << first << "\nsecond: " << second
              << std::endl;

    return 0;
}

Result


Related Tutorials