The Strrev function in C + +

Source: Internet
Author: User

The Strrev function in C + +

There is a function strrev in C + +, which reverses the string implementation, but keep in mind that the Strrev function is valid only for character arrays and is not valid for string types.


See the code below, where I've implemented it myself:


#include <iostream> #include <string>using namespace std; int main () {char s[100] = "China"; cout<<s<<endl; Strrev (s); cout<<s<<endl;/* Strrev cannot use string str= "China" for string type; cout<<str<<endl; Strrev (Str.c_str ());cout<<str<<endl; */char str[100]= "China"; cout<<str<<endl; int head=0, Tail=strlen (str)-1; for (; head<tail; head++, tail--) {swap (Str[head], str[tail]);} cout<<str<<endl; return 0; }





The Strrev function in C + +

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.