hello
i write a program to take two user inputs. First input is your first name, and the second input is your family name. and check if both the inputs are same or not.
it work fine this
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char firstName[20];
char familyName[20];
char fullName[40];
cout << "Enter your first name" << endl;
cin >> firstName;
cout << "Enter your family name" << endl;
cin >> familyName;
bool check = strcmp(firstName, familyName);
if (!check) {
cout << "Error - You have input same string as first and family name";
} else {
strcpy(fullName, firstName);
strcat(fullName, " ");
strcat(fullName, familyName);
cout << "Your full name is " << fullName << endl;
}
return 0;
}
now i want the name print out in reverse, the full name in reverse order by reversing the order of characters.
how can i do it ??
also for the ouput why not just use for starting from the end, just kidding
I havent test this but
1 2 3 4 5 6 7 8 9 10
#include <iostream>
#include <algorithim> //for std::reverse
#include <string> /*better than cstring might come down to personal though but this is the standard*/
int main()
{
std::string lol = "olleh";
std::reverse(lol.begin(), lol.end());
std::cout << lol; //should be hello
}
Another option: std::experimental::ostream_joiner http://en.cppreference.com/w/cpp/experimental/ostream_joiner
sorry to bang on about this but the nice thing here is that it allows delimiters b/w individual elements of the string that is not possible with the std::ostreambuf_iterator AFAIK.
There are also some interesting differences with std::ostream_iterator, viz:
Compared to std::ostream_iterator, ostream_joiner prints the delimiter sequence one fewer time, and is not templated on the type of the object to be printed.
But being experimental I suppose it's not a full-fledged member of the standard (yet):
hello
thank you all for your help
but my teacher he say today i need to print the in reverse order bu using (for loop) i will try it and see if i can make it work.