c++ - Print out vector of strings backwards -


i trying write program takes in user input, store vector of strings, , prints out vector according functions.

for function, "display_backwards", supposed display input of user in mirrored-like image.

i'm having trouble writing code , it's giving me errors don't understand why

this code:

void asci_art::display_backwards(vector<string> art) { char swap[100]; cout << "your artwork in mirrored image" << endl; cout    << "=============================" <<endl;  (unsigned int i=0; < art.size(); i++) {     for(int j=0; j < art[i].size(); j++)     {          swap[j] = art[i].end()-j;         art[i].begin()+j = swap[j];     } }  for(int k= 0; k < swap.size(); k++) {     cout << swap[k]; } cout << endl; 

}

the function written in class

the vector, art, has user input. , each element of vector, stores line of string want access string of element , swap letters of string, believe create mirrored image.

i compiling errors such "cannot convert _normal iterator> char" don't understand why because dealing chars, same type. "no such operation '='" ??

not understanding why. can explain? or maybe logic wrong, can me rewrite it?

bare me, not great in c++. appreciate help.

edit: sorry. forgot mention want reflect/mirror vertically

use std::reverse reverse each string in vector.

void asci_art::display_backwards(vector<string> art) {   for( auto&& : art ) {     std::reverse(a.begin(), a.end()); // reverses each string     std::cout << << std::endl;   } } 

or if want reverse order of strings in vector, different call reverse trick.

void asci_art::display_backwards(vector<string> art) {   std::reverse( art.begin(), art.end() );  // reverses order of strings in vector   for( auto const& : art ) {     std::cout << << std::endl;   } } 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -