c++ - Program won't compile -


Below I have a code in C ++, which is to reverse the argument in a vector, but not the sequence is. I listed my problems in the code given below as sidenotes Invert function is considered to overturn each argument, and then the main function only outputs inverted words in the same sequence, for example, the program ("One Two three four ") = ruof eerth owt eno

  # include & lt; Iostream & gt; #include & lt; String & gt; using namespace std; Int Invert (string general) {string inverted; For (intu = common siz () - 1; num> gt; = 0; num--) {inverted.append (normal [number]); // I do not know how to get each character // I need another command for append) return ** Inverted **; & Lt; ----} int main (int argc, char * argv []) {string text; For (int a = 1; a & lt; argc; a ++) {text.append (invert (argv [A])); // analog function text.append ("") can not be run; } Cout & lt; & Lt; Text & lt; & Lt; Endl; Return 0; }  

The problem is that is normal [num] a character. There is no surcharge for attachment () letters.

You can use inverted.push_back (normal [number]); See

.

I should add some other notes:

0) Why are you returning from int the opposite () ? Reverse is a string, so you should return a string:

  `string inversion (string normal);`  

Instead of using num to reinforce 1) , you can use reverse_title :

 for  (String :: reverse_iterator) can use C = normal.rbegin (); C! = Normal.rend (); ++ c) {inverted.push_back (* c); } }  

2) are not modified in the function while passing strings in the function, so you have to go through the context to avoid additional string copies.

  string invert (const string and normal);  

3) You are crossing 0..argc , so what will be behind your expectations of the strings mentioned above, if I understand your needs properly.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -