c++ - Resolution/size of string -
i'm trying write mini program takes vector of strings (from user input) , displays or prints out increased & decreased resolution (size) of it.
it increase or decrease each character of each string 4. example: if string "abcdef" increased resolution "aaaabbbbccccddddeeeeffff"
i having trouble writing code. don't want not loop through vector of strings want read characters of each string in vector , produce resolution results.
is there anyway of doing that? keep getting these conversion errors compiler
void asci_art::bigresol(vector<string>art) { cout << "increased resolution of artwork" <<endl; (int = 0; < art.size(); i++) { for(int j = 0; j < art[i].size(); j++) { cout << art[j] + art[j] + art[j] + art[j] << endl; } } }
btw wrote function in class.
in case, i'm writing function increases resolution. assume decreasing resolution same idea.
you're concatenating strings instead of concatenating characters. form string need each character instead of each string:
std::cout << std::string(4, art[i][j]); //put newline in outer loop
you should consider having parameter const std::vector<std::string> &
avoid unnecessary copies when calling function. consider using nice range-for syntax, introduced in c++11:
for (const auto &str : art) { (auto c : str) { std::cout << std::string(4, c); } std::cout << '\n'; //put newline in between each transformed string }
Comments
Post a Comment