Search
 
SCRIPT & CODE EXAMPLE
 

CPP

reverse c++ string

#include <algorithm>
#include <iostream>
#include <string>

int main()
{
    std::string foo("foo");
    std::string copy(foo);
    std::cout << foo << '
' << copy << '
';

    std::reverse(copy.begin(), copy.end());
    std::cout << foo << '
' << copy << '
';
}
Comment

how to reverse a string in c++

string reverse(string str)
{
    string output;
    
    for(int i=str.length()-1; i<str.length(); i--)
    {
        output += str[i];
    }
    return output;
}
Comment

reversing a string in C++

string name1 = "Sam" ;

string name2 = name1 ;    /// Have to store the ORIGINAL in 	ANOTHER  variable   ...then Reverse that

reverse(name2.begin(),name2.end()) ;

cout << name2 ;    		// maS
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ float and double 
Cpp :: constructor in cpp 
Cpp :: C++ Increment and Decrement 
Cpp :: cpp vector 
Cpp :: Visual studio code include path not working c++ 
Cpp :: c++ split string by space into array 
Cpp :: c++ preprocessor operations 
Cpp :: size() in c++ SET 
Cpp :: c++ syntax 
Cpp :: c++ get whole line 
Cpp :: How to turn an integer variable into a char c++ 
Cpp :: reverse an array in c++ stl 
Cpp :: enum c++ 
Cpp :: prime or not in cpp 
Cpp :: why do we use pointers in c++ 
Cpp :: how to grab each character from a string 
Cpp :: put text on oled 
Cpp :: opencv cpp create single color image 
Cpp :: c++ string_t to string 
Cpp :: print reverse number 
Cpp :: cmd color text c++ 
Cpp :: sliding window c++ 
Cpp :: Array declaration by specifying the size in C++ 
Cpp :: count number of char in a string c++ 
Cpp :: STD::ERASE FUNCTION IN C++ 
Cpp :: DSA 2. Complexity Analysis Google drive Educative excellent courses!!!! [Educative.io] Competitive Programming in C++ The Keys to Success 
Cpp :: the difference between i++ and ++i 
Cpp :: phi function (n log (log(n))) 
Cpp :: memset c++ 
Cpp :: binary to decimal online converter 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =