同时打印多行C
Printing multiple lines at the same time C++
本文关键字:打印 更新时间:2023-10-16
#include <iostream>
#include <Windows.h>
#include <string>
using namespace std;
void slowPrint(unsigned long speed, const char *s)
{
int i = 0;
while(s[i]!=0)
{
cout << s[i++];
cout.flush();
Sleep(speed);
}
}
int main()
{
char choice;
cout << "================================================================================n";
slowPrint(80, " "Words being said"nn");
cout << "================================================================================n";
cin >> choice;
return 0;
}
所以我想知道我是否可以以某种方式同时打印19-21。而不是只让第一个" === ..."打印出来,而是从第20行中键入慢速,最后是代码的末尾。
或者是否有一种方法甚至可以输出两个" ==="条,然后慢慢键入它们之间的界线。
如果可以的话,请提供帮助!
谢谢。
(您可能会对它的措辞感到困惑,但很难解释。我可以在需要时尝试深入解释。)
将奇特事物打印到终端屏幕上的一种方法是使用逃生序列。如果您曾经想知道键盘如何告诉计算机有关箭头键输入,即使没有针对这些操作的ASCII键,Escape sequences是答案。
逃生序列是从逃生字符或ASCII值开始的27.要向上移动光标,您需要以下几行:
char esc(27); //You need to initialize the escape character by calling its ASCII value
std::cout << esc << "[1A" // This line moves the cursor up.
<< "r"; // This line moves the cursor all the way back to the left.
因此,为了获得所需的输出,请尝试以下主体:
char Choice,ESC(27);
std::cout << "================================================================================nn"
<< "================================================================================"
<< esc << "[1Ar";
slowPrint(1, " "Words being said"nn");
std::cin >> choice;
return 0;
有许多逃生序列可用于控制您的终端。例如,尝试打印以下逃生序列,然后是其他一些文本。
"[1;31m"
有关更多逃生序列,请参见以下链接。
http://ascii-table.com/ansi-escape-sequences.php
相关文章:
- 如何循环打印顶点结构
- 为什么在popback()操作之后,它仍然打印完整的矢量
- 如何在c++中打印目录
- 有一个打印语句的函数是一种糟糕的编程实践吗
- 在线编译器中的分段C++没有打印消息
- 在C++中打印指向不同基元数据类型的指针的内存地址
- 这个指针和内存代码打印是什么?我不知道是打印垃圾还是如何打印我需要的值
- 如何将结构插入到集合中并打印集合的成员
- 在循环C++中指定字符串之后,不会打印该字符串
- 以螺旋方式打印矩阵的程序.(工作不好)
- 从控制台中删除最后打印的元素
- 如何使用Crypto++并为RSA返回可打印的字节/字符数组
- 如何仅使用对象名称打印特定于对象的成员
- 回溯C++不打印函数,因此文件
- 在一定长度后从数组中打印时缺少整数
- 为什么这个 c++ 代码打印出长度 5,当我打印出字符串时,程序会自动终止?
- 在gem5中打印文件中的所有cache_blocks
- 打印数字图案
- Log4cpp:以UTC/GMT时区打印日期
- 如何使用gdb制作一个可以漂亮地打印每个对象的C++函数