Strings

  • + 5 comments

    Upvoted for (after ignoring #include <bits/stdc++.h>!)

    swap( a[0], b[0] );
    

    I personally did it this way:

    cout << b.at(0) << a.substr(1) << ' ';
    cout << a.at(0) << b.substr(1) << endl;
    

    I know that mine would throw out_of_range but what happens, with your solution, if a or b is empty?

    By the way, for anyone wondering: string::size() and string::length() are exactly the same function! Which is pretty uncommon ...