VB icon

Reverse a string

Email
Submitted on: 2/28/2020 11:53:39 AM
By: Thomas1965 
Level: Beginner
User Rating: Unrated
Compatibility: C++ (general)
Views: 767
 
     This demo lets the user enter text and displays it reversed. Written with GCC 8.2 but should work with any modern C++ compiler.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Reverse a string
// Description:This demo lets the user enter text and displays it reversed. 
Written with GCC 8.2 but should work with any modern C++ compiler.
// By: Thomas1965
//**************************************

#include <cstdio>
#include <iostream>
#include <string>
int main()
{
	std::cout << "\n\t\tReverse String Version 1.0";
	std::cout << "\n\t\t===================";
	std::cout << "\n\t\tEnter a string: ";
	
	std::string input;
	std::getline(std::cin, input);
	
	std::cout << "\n\t\tOriginal text: " << input << "\n";
	// To reverse the string we simply create a new string 
	// using the reverse iterator of the string class.
	// An alternative would be using the STL algorithm std::reverse.
	std::string output(input.rbegin(), input.rend());
	
	std::cout << "\n\t\tReversed text: " << output << "\n";
	std::cout << "\n\n\t\tHit any key to exit."; 
	std::getchar();
}


Other 31 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.