如何制作C++菜单文本

How to make C++ menu text

本文关键字:文本 菜单 C++ 何制作      更新时间:2023-10-16

我正在制作一款基于文本的冒险游戏。我想让游戏名称(被困)大或由线条组成。我该怎么做?

我想要的一个例子是这样的:

╔═╗╔═╗───╔╗──────╔╗────╗─╔╗──╃╗──╗╔╗╗

╃╗────╔═══╦╗ ║║╚╝║║───║║────────║║────║║─║║──║║║║────╚╗╔╗║║ ║╔╗╔╗╠══╦╣║╔╦══╦╗─╔╣║╔══╗║╚═╝╠══╣║║║╔══╗─║║║║╚═╦══╦══╦══╗* ║║║║║║╔╗╠╣╚╝╣╔╗║║─║║║║╔╗║║╔═╗║║═╣║║║║╔╗║─║║║║╔╗║╔╗║╔╗║║═╣ ║║║║║║╔╗║║╔╗╣╔╗║╚═╝║╚╣╔╗║║║─║║║═╣╚╣╚╣╔╗║╔╝╚╝║║║║╚╝║╚╝║║═╣ ╚╝╚╝╚╩╝╚╩╩╝╚╩╝╚╩═╗╔╩═╩╝╚╝╚╝─╚╩══╩═╩═╩╝╚╝╚═══╩╝╚╩══╣╔═╩══╝ ───────────────╔═╝║───────────────────────────────║║ ──────

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

但更明显。而且当它被编译时,它会在?的中出现。 所以我需要文本对编译器友好。

在 Windows 上,使用宽字符串文字:

wchar_t * titleStr= L"╔═╗╔═╗───╔╗────────╔╗────╔╗─╔╗──╔╗╔╗────╔═══╦╗n"
                    L"║║╚╝║║───║║────────║║────║║─║║──║║║║────╚╗╔╗║║n"
                    L"║╔╗╔╗╠══╦╣║╔╦══╦╗─╔╣║╔══╗║╚═╝╠══╣║║║╔══╗─║║║║╚═╦══╦══╦══╗*n"
                    L"║║║║║║╔╗╠╣╚╝╣╔╗║║─║║║║╔╗║║╔═╗║║═╣║║║║╔╗║─║║║║╔╗║╔╗║╔╗║║═╣ n"
                    L"║║║║║║╔╗║║╔╗╣╔╗║╚═╝║╚╣╔╗║║║─║║║═╣╚╣╚╣╔╗║╔╝╚╝║║║║╚╝║╚╝║║═╣ n"
                    L"╚╝╚╝╚╩╝╚╩╩╝╚╩╝╚╩═╗╔╩═╩╝╚╝╚╝─╚╩══╩═╩═╩╝╚╝╚═══╩╝╚╩══╣╔═╩══╝ n"
                    L"───────────────╔═╝║───────────────────────────────║║ n"
                    L"───────────────╚══╝───────────────────────────────╚╝n"
std::wcout<<titleStr;

有多种方法可以做到这一点。

最简单的方法是在此处使用 cout (char)#include <iostream> #include <fstream> #include <string> int main() { std::ifstream reader("art.txt"); //Load the text std::string art = parseart(reader); //Parse the file std::cout << art << std::endl; //Print reader.close(); return 0; } std::string parseart(std::ifstream& File) { std::string parsedfile; if(File) { while(File.good()) { std::string tmpline; std::getline(File, tmpline); tmpline += "n"; parsedfile += tmpline; } return parsedfile; } else { //Error }