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

Reverse string C++

reverse(str.begin(),str.end());
Comment

reverse string c++

#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string str;
  getline(cin,str);
  reverse(str.begin(),str.end());
  cout<<str;
}
Comment

How to reverse a string in c++ using reverse function

#include <iostream>
//The library below must be included for the reverse function to work
#include<bits/stdc++.h> 
using namespace std;

int main() {
  
  string greeting = "Hello";
  //Note that it takes the iterators to the start and end of the string as arguments
  reverse(greeting.begin(),greeting.end());
  cout<<greeting<<endl;
}
Comment

reverse string c++

#include <iostream>
#include <cstring>

using namespace std;

void palindrome(string word){
   string reversed=word;
    for (int i = 0, j = word.length() - 1; i < word.length(), j >= 0; i++, j--) {
        reversed[j] = word[i];
    }
    cout<< reversed<<endl;
     if(word==reversed)
         cout<<"Palindrome";
     else cout<<"not palindrome";
  
}

int main(){
    string text;
    cout<<"Enter text: ";                                       
    getline(cin,text);                                          
    reverse(text);
}
Comment

reverse function in cpp string

// C++ program to illustrate the
// reversing of a string using
// reverse() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string str = "geeksforgeeks";
 
    // Reverse str[begin..end]
    reverse(str.begin(), str.end());
 
    cout << str;
    return 0;
}
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

c++ reverse string

#include <iostream>
#include <string>
using namespace std;
void REVERSE(string word){
   string reversed = word;
   int n = word.length();
   int t = 0;
    for (int i = n - 1;i >= 0; i--) {
        reversed[t++] = word[i];
    }
    cout << reversed << "

";
     if(word==reversed)
         cout<<"Palindrome";
     else cout<<"not palindrome"; 
}
int main(){
    string text;
    cout<<"Enter text: ";                                       
    getline(cin,text);                                          
    REVERSE(text);
}
Comment

Reverse words in a given string solution in c++

#include<iostream>
#include<stack>
using namespace std;

string reverseWords(string S)
{
	stack<char> s;
	string ans;
	for (int i = S.length()-1; i >= 0; i--)
	{
		if (s.empty())
		{
			s.push(S[i]);
		}
		else if (!(s.empty()))
		{
			if (s.top() == '.')
			{
				s.pop();
				while (!(s.empty()))
				{
					ans += s.top();
					s.pop();
				}
				ans += '.';
			}
			
			s.push(S[i]);
	
		}
	}
	while (s.size())
	{
		ans += s.top();
		s.pop();
	}
	return ans;
}
int main()
{
	string s;
	cout << "Enter string: ";
	cin >> s;

	string result;
	result = reverseWords(s);
	cout << "result: " << result << "
";

	return 0;
}
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

c++ reverse string

#include <iostream>
#include <string>
using namespace std;
void REVERSE(string word){
   string reversed = word;
   int n = word.length();
   int t = 0;
    for (int i = n - 1;i >= 0; i--) {
        reversed[t++] = word[i];
    }
    cout << reversed << "

";
     if(word==reversed)
         cout<<"Palindrome";
     else cout<<"not palindrome"; 
}
int main(){
    string text;
    cout<<"Enter text: ";                                       
    getline(cin,text);                                          
    REVERSE(text);
}
Comment

344. Reverse String c++

class Solution {
public:
    void reverseString(vector<char>& s) {
        int i=0;
        int j=s.size()-1;
        while(i<j)
        {
            swap(s[i],s[j]);
            i++;
            j--;
        }
    }
};

//Runtime: 20 ms, faster than 76.31% of C++ online submissions for Reverse String.
//Memory Usage: 23.3 MB, less than 38.31% of C++ online submissions for Reverse String.
Comment

c++ reverse string

#include <iostream>
#include <string>
using namespace std;
void palindrome(string word){
   string reversed = word;
   int n = word.length();
   int t = 0;
    for (int i = n - 1;i >= 0; i--) {
        reversed[t++] = word[i];
        //t++;
    }
    cout << reversed << "

";
     if(word==reversed)
         cout<<"Palindrome";
     else cout<<"not palindrome"; 
}
int main(){
    string text;
    cout<<"Enter text: ";                                       
    getline(cin,text);                                          
    palindrome(text);
}
Comment

c++ Write a program to reverse an array or string

// Iterative C++ program to reverse an array
#include <bits/stdc++.h>
using namespace std;
 
/* Function to reverse arr[] from start to end*/
void rvereseArray(int arr[], int start, int end)
{
    while (start < end)
    {
        int temp = arr[start];
        arr[start] = arr[end];
        arr[end] = temp;
        start++;
        end--;
    }
}    
 
/* Utility function to print an array */
void printArray(int arr[], int size)
{
   for (int i = 0; i < size; i++)
   cout << arr[i] << " ";
 
   cout << endl;
}
 
/* Driver function to test above functions */
int main()
{
    int arr[] = {1, 2, 3, 4, 5, 6};
     
    int n = sizeof(arr) / sizeof(arr[0]);
 
    // To print original array
    printArray(arr, n);
     
    // Function calling
    rvereseArray(arr, 0, n-1);
     
    cout << "Reversed array is" << endl;
     
    // To print the Reversed array
    printArray(arr, n);
     
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ program to print natural numbers from 1 to 10 in reverse order using while loop 
Cpp :: modulo subtraction 
Cpp :: how to search in array c++ 
Cpp :: power of two c++ 
Cpp :: how do you wait in C++ 
Cpp :: c++ insert into map 
Cpp :: selection sort c++ algorithm 
Cpp :: c++ input 
Cpp :: json::iterator c++ 
Cpp :: c++ back() 
Cpp :: integer to char c++ 
Cpp :: new c++ 
Cpp :: c ifdef 
Cpp :: tree to array c++ 
Cpp :: descending order c++ 
Cpp :: position of max element in vector c++ 
Cpp :: how to cout in c++ 
Cpp :: travelling salesman problem c++ 
Cpp :: pointer cpp 
Cpp :: 31. Next Permutation leetcode solution in c++ 
Cpp :: map in cpp 
Cpp :: c++ template 
Cpp :: passing custom function in sort cpp 
Cpp :: c++ forbids comparison between pointer and integer 
Cpp :: initialising 2d vector 
Cpp :: c++ string_t to string 
Cpp :: min heap stl 
Cpp :: accumulate in cpp 
Cpp :: find maximum sum in array of contiguous subarrays 
Cpp :: if else in c++ 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =