+ 2

How to reverse string? C++

If I input daphnyzyb and reversed like byzynhpad?

14th Mar 2017, 2:27 PM
Daphnyzyb Pelaez
Daphnyzyb Pelaez - avatar
3 Answers
14th Mar 2017, 2:29 PM
Hatsy Rei
Hatsy Rei - avatar
+ 3
thank you!!
14th Mar 2017, 2:33 PM
Daphnyzyb Pelaez
Daphnyzyb Pelaez - avatar
+ 1
// C int main() { char str[]="ha"; // source string int l=strlen(str)-1; if (l<1) return 1; for (int i = 0; i < l; ++i, --l) { str[i] ^= str[l] ^= str[i] ^=str[l]; } cout << str << endl; return 0; } //C++ int main() { char* str = "hack"; // source string reverse_copy(str, str + strlen(str), ostream_iterator<char>(cout)); return EXIT_SUCCESS; }
15th Mar 2017, 1:20 AM
Dare-devil
Dare-devil - avatar