started a new thread because naru got my interest. please explain.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
void reverseword(char * reverse) {
size_t size = strlen(reverse); //get the size of the char *
for(size_t i = 1; i <= size; i++)
{
cout << reverse[size - i]; //output the word
}
}
void reverseword (string reverse) {
size_t size = reverse.size();
string::reverse_iterator walkword;
for(walkword = reverse.rbegin(); walkword < reverse.rend(); walkword++)
{
cout << *walkword;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
cout << "Method one for string reversal" << endl;
cout << "==============================" << endl;
cout << "== Using Char * and cin.getline" << endl;
cout << "== using for statement to itterate" << endl;
cout << "==============================" << endl;
char * getwords = new char(); //will hold the words
cout << "Please enter the words to reverse" << endl << endl << endl;
cin.getline(getwords,100); //get the word(s) to reverse
reverseword(getwords); //reverse the words
cin.sync();//clean up buffer for next example
cout << endl << endl << endl;
cout << "Method Two for string reversal" << endl;
cout << "==============================" << endl;
cout << "== Using std::basic_string cin.getline" << endl;
cout << "== using build in itterator members" << endl;
cout << "==============================" << endl;
string getwordsagain;
cout << "Please enter the words to reverse" << endl << endl << endl;
getline(cin, getwordsagain);
reverseword(getwordsagain);
cin.sync(); //clean the buffah
return 0;
}
cheers!