如何将输出设置为中间
How to set output to middle?
是否可以编写代码将输出的文本格式化为屏幕中间?我试了很多,但都没用。以下是我到目前为止的想法。
cout.setf (ios::middle);
那是个错误。我也试过
setw(10);//etc.
但我对使用setw命令有点陌生,所以我不知道如何正确使用它。
更新:
//The Game of 4 Seasons
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
cout << "Welcome to this gamennn";
system ("pause");
system ("cls");
cout << "CAUTION!nn";
cout << "The adventure you are about to embark contains high levels of:n";
cout << "Funn";
cout << "Adventuren";
cout << "Excitementnnn";
cout << "If you have a record of buzz killing or anything similar, nthen this game is NOT for you.nnnn";
system ("pause");
return 0;
}
Q:是否可以编写代码将输出的文本格式化为屏幕中间?
A: 是的。而不是直接用"cout"。但当然有类似ncurses:的东西
-
http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/
-
http://invisible-island.net/ncurses/ncurses-intro.html
就我自己而言,我更喜欢诅咒。
但根据您的需求有多复杂,您可能会考虑ansi终端模拟。。。大多数系统都有它们。(在Ubuntu上,它被称为gnome终端")
然后您可以使用ansi终端控制进行输出。例如,
void gotoxy(int col, int row)
可以输出esc字符,后跟"["和行(即"12"),后跟";"和列号("40")后面跟着"H"。
用户输入将是std::cin。
这不是一个很好的解决方案,但有一些功能。
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 在C++/Linux中设置单调时钟的一些技巧
- 2D数组来自文本输入,中间有空格
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 嵌套在类中时无法设置成员数据
- 需要帮助设置在C++中使用的Potrace
- 如何在自删除后将对象设置为nullptr
- 将指针设置为"nullptr"并不能防止双重删除?
- 如何在Ubuntu中使用cmake设置qt4
- ld:bind_at_load和-bitcode_bundle(Xcode设置ENABLE_bitcode=YES)不能
- 如何在boost beast http请求中设置http头
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- 如何将这个C++哈希表转换为动态扩展和收缩,而不是使用硬设置的最大值
- 为什么文件名被设置为一个点,而不是在读取矢量中的文件名时
- 如何在24位SDL_Surface上设置像素的颜色
- std::设置自定义比较器
- 如何设置一个范围来提取我想要获得的信息
- 如何将项目属性设置为删除警告MSB8004:中间目录不会以落后的斜线结束
- 如何将输出设置为中间
- 在打开文件对话框中设置过滤器,中间有通配符(*)