"C + +" with the stack implementation of reverse output a string (can be with spaces)
idea:
1. Use string and getline to get a line of text with spaces
2. Convert a string to char*
3. Will char* into the stack
4. The stack of elements can be realized in flashback output
/* Get a line of text, with the stack reverse output this line of text * * *
#include <iostream>
#include <stack>//use the stacks inside the standard library
#include < cstring>
#include <string>
using namespace std;
int main ()
{
string temp;
Getline (cin,temp)//Get a line of text
int len = temp.size () that may contain spaces
; const char *SS = TEMP.C_STR ();//convert String to char*
stack <char> text;
int i = 0;
while (len--) {//into stack
Text.push (ss[i++]);
}
while (!text.empty ()) {//out stack
cout << text.top ();
Text.pop ();
}
return 0;
Welcome comments, Welcome to the exchange.