visual c++ - How can I simplify my C++ code to reverse characters? -


Hello, I have this program that I change the letter I enter. I am using iostream . Can I do it another way and iostream and cin.getline to cin> and gt; X?

My code:

  // header files # include & lt; Iostream & gt; #include & lt; string & gt; using namespace std; // Recursive function definition which is taking input / reference parameters of a reference / type. Zero reverse print (iStream & amp;); // main function int main () {// printing cout & lt; & Lt; "Please enter a series of letters after a period of time. ':"; // Recursive function reverse print call (conn); The court's & lt; & Lt; Endl & lt; & Lt; Endl; Return 0; } // recursive function implementation which is taking the / reference type of an input reference parameter // After calling this function several times, a stage // will come when the last function call will be returned / after that the final character will be printed before and even then. Zero reverseprint (ice cream and scene) {four c; // input stream will retrieve a single character from cin.get (c); // If the character is either or the key is entered i.e '\ n' then the // function will be returned if (c == '.' || c == '\ n') {cout & lt; & Lt; Endl; Return; } // Again call the recursive function as the parameter with the // input stream. ReversePrint (CIN); // Print Character C on the screen. The court's & lt; & Lt; C; } 

The bottom function gets linear from the standard input, it reverses and stdout Writes to

  #include & lt; Algorithm & gt; #include & lt; String & gt; # Include & lt; Iostream & gt; Int main () {std :: string line; Std :: getline (std :: cin, line); Std :: reverse (line.begin (), line.end ()); Std :: cout & lt; & Lt; Line & lt; & Lt; Std :: endl; }  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -