You are viewing a single comment's thread. Return to all comments →
Upvoted for (after ignoring #include <bits/stdc++.h>!)
#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?
out_of_range
a
b
By the way, for anyone wondering: string::size() and string::length() are exactly the same function! Which is pretty uncommon ...
string::size()
string::length()
Seems like cookies are disabled on this browser, please enable them to open this website
Strings
You are viewing a single comment's thread. Return to all comments →
Upvoted for (after ignoring
#include <bits/stdc++.h>
!)I personally did it this way:
I know that mine would throw
out_of_range
but what happens, with your solution, ifa
orb
is empty?By the way, for anyone wondering:
string::size()
andstring::length()
are exactly the same function! Which is pretty uncommon ...