Specifying character

Posted by danutenshu on Stack Overflow See other posts from Stack Overflow or by danutenshu
Published on 2010-06-14T20:01:22Z Indexed on 2010/06/14 20:02 UTC
Read the original article Hit count: 224

Filed under:
|
|

So below I have a code in C++ that is supposed to invert the arguments in a vector, but not the sequence. I have listed my problems as sidenotes in the code below. The invert function is supposed to invert each argument, and then the main function just outputs the inverted words in same order For instance, program("one two three four")=ruof eerth owt eno

 #include <iostream>
 #include <string>
 using namespace std;

 int invert(string normal)
{
     string inverted;
     for (int num=normal.size()-1; num>=0; num--)
     {
         inverted.append(normal[num]);    //I don't know how to get each character
                                          //I need another command for append
     }
     return **inverted**;  <----
 }

 int main(int argc, char* argv[])
 {
     string text;
     for (int a=1; a<argc; a++)
     {
         text.append(invert(argv[a])); //Can't run the invert function
         text.append(" ");
     }
     cout << text << endl;
     return 0;
 }

© Stack Overflow or respective owner

Related posts about c++

Related posts about strings