将"ascii art"打印 f放入字符数组中?
putting an "ascii art" printf into a char array ?
我有这个对象
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;
}
相关文章:
- 指向指向字符数组的指针数组的指针
- 比较字符数组
- 如何使用Crypto++并为RSA返回可打印的字节/字符数组
- 使用无符号字符数组有效存储内存
- 错误:字符数组的初始值设定项太多
- 对字符数组中的元素执行逐位操作
- C++ 无法在字符数组中使用 for 循环打印字母模式
- 如何在 C++ 中从文件中读取字符数组(带有一些空格)
- C++ 传递二维字符数组
- 无法在 C++ 中输入字符数组
- 字符数组中的元素数
- 我的目标是编写一个程序来计算和存储字符串在字符数组中出现的位置
- 使用字符数组作为 Map 中的键
- C++:__aligned(__alignof__) 导致字符数组数据出现问题?
- 按顺序声明的字符数组重叠
- 在 C++ 中字符串的大小与字符数组的大小
- 寻找一种更好的方法来表示无符号字符数组
- 如何打印 2D 字符数组C++
- 从字符数组的元素中减去'a'是什么意思
- 我是否不正确地集中了这些字符数组?