I am trying to generate ASCII art given a string.
art.cpp
#pragma once
#include <string>
#include <vector>
#include "art.h"
std::string Art::display(std::string& text) {
std::string final_text;
final_text.reserve(text.length());
for (char letter: text) {
std::string single = letters[letter];
/* tried this */ single.erase(std::remove(single.begin(), single.end(), '\n'), single.end());
final_text += single;
}
return final_text;
}
art.h
#pragma once
#include <string>
#include <vector>
#include <map>
class Art {
public:
std::map<char, std::string> letters = {
std::make_pair('a', std::string(R"(
_
/ \
/ _ \
/ ___ \
/__/ \__\
)")),
std::make_pair('b', std::string(R"(
____
| __ )
| _ \
| |_) |
|____/
)")),
std::make_pair('c', std::string(R"(
____
/ ___|
| |
| |___
\____|
)")),
std::make_pair('d', std::string(R"(
____
| _ \
| | | |
| |_| |
|____/
)")),
std::make_pair('e', std::string(R"(
_____
| ____|
| _|
| |___
|_____|
)")),
std::make_pair('f', std::string("asdf")),
std::make_pair('g', std::string("asdf")),
std::make_pair('h', std::string(R"(
_ _
| | | |
| |_| |
| _ |
|_| |_|
)")),
std::make_pair('i', std::string("asdf")),
std::make_pair('j', std::string("asdf")),
std::make_pair('k', std::string(R"(
_ __
| |/ /
| ' /
| . \
|_|\_\
)")),
std::make_pair('l', std::string("asdf")),
std::make_pair('m', std::string("asdf")),
std::make_pair('n', std::string("asdf")),
std::make_pair('o', std::string(R"(
___
/ _ \
| | | |
| |_| |
\___/
)")),
std::make_pair('p', std::string("asdf")),
std::make_pair('q', std::string("asdf")),
std::make_pair('r', std::string(R"(
____
| _ \
| |_) |
| _ <
|_| \_\
)")),
std::make_pair('s', std::string("asdf")),
std::make_pair('t', std::string("asdf")),
std::make_pair('u', std::string("asdf")),
std::make_pair('v', std::string("asdf")),
std::make_pair('w', std::string("asdf")),
std::make_pair('x', std::string("asdf")),
std::make_pair('y', std::string(R"(
__ __
\ \ / /
\ V /
| |
|_|
)")),
std::make_pair('z', std::string("asdf"))
};
std::string display(std::string& text);
};
This is taking a str reference in then looping over each character and finding that character in the map and getting its corresponding ASCII art letter then adding it to a final string.
This presents a problem. It prints each character on a new line when I want to print the string Art::display()
returns.
What I have tried? I have tried removing the newlines but that jumbles bits and pieces together/apart.
What i want it to do? I want it to print a word left to right and not each char on a new line.