我有这个对象
void Game::Logo(void)
{
printf(" _ _ n");
printf(" (_|_)n");
printf(" __ _ ___ ___ _ _ n");
printf(" / _` / __|/ __| | |n");
printf(" | (_| __ (__| | |n");
printf(" __,_|___/___|_|_|n");
printf(" n");
printf("n");
}
为了让我从中创建一个数组,我必须遍历每一行并在任何内容之间放置一个,'',
,当我使用的实际名称要大得多时,这将需要很长时间并且容易出现人为错误。
我将如何创建一个函数,它可以为我完成这一切而不会出错,并且根据"徽标"的大小可能有不同的数组大小选项。
我会将每行都存储到一个字符串中吗:
string row0 = " _ _ ";
string row1 = " (_|_)";
string row2 = " __ _ ___ ___ _ _ ";
string row3 = " / _` / __|/ __| | |";
string row4 = " | (_| __ (__| | |";
string row5 = " __,_|___/___|_|_|";
string row6 = " ";
然后创建此类函数:
printfToArray(int numRow,int numCol, string rows)
{
for (int i = 0; i < numRow; i++)
{
//create an array of char logo[numRow][numCol]
//numCol is the number of max space require, so this case, 23 because of n as well
//then copy it somehow into the array within loop
}
}
int numRow = 7; //because 7 strings
因为这些似乎是我能远程想到的唯一方法,但即便如此,我也不明白我将如何做到这一点。
您可以使用std::vector
将行放在数组中
#include <iostream>
#include <string>
#include <vector>
int main()
{
std::vector<std::string> vs
{
R"( _ _ )",
R"( (_|_))",
R"( __ _ ___ ___ _ _ )",
R"( / _` / __|/ __| | |)",
R"( | (_| __ (__| | |)",
R"( __,_|___/___|_|_|)",
R"( )"
};
for (auto s : vs)
std::cout << s << "n";
return 0;
}