安慰#

介绍#

控制台用于显示 VEX V5 C++ 项目的文本输出。

  • 在 VEXcode V5 中,控制台输出会显示在监视器窗口中。

  • 在 VS Code 中,控制台输出会显示在终端中。

当一个新项目开始运行时,光标会从控制台的第 1 行开始。

函数#

可以使用以下函数在控制台中打印文本:

  • printf – Print text to the console.

printf#

使用当前光标位置在屏幕上打印文本。

Available Functions
void printf(const char *value);

Parameters

范围

类型

描述

value

const char*

用于将文本和值打印到控制台的格式字符串。

Return Values

此函数不返回值。

Notes
  • 只有当出现新行时,文本才会发送到控制台。

// Print a message to the console
printf("Hello, robot!");
// Print a new line to the console
printf("\n");

控制序列#

该控制台支持用于格式化和屏幕控制的 ANSI 控制序列。

Clear console#

By printing \033[2J, everything inside the console will be cleared.

Examples
// Print to the console, then clear it after
// 2 seconds
printf("VEXcode");
wait(2, seconds);
printf("\033[2J\n");

Change the Font Color#

您可以使用以下命令序列更改打印到控制台时的字体颜色:

  • \033[30m — Black

  • \033[31m — Red

  • \033[32m — Green

  • \033[33m — Yellow

  • \033[34m — Blue

  • \033[35m — Purple

  • \033[36m — Cyan

  • \033[37m — White

  • \033[91m — Orange

  • \033[97m — Transparent

Notes
  • All color codes need to follow an escape sequence \033 in order to function.

Examples
// Print VEXcode in Red to the console
printf("\033[31mVEXcode");

// Set the console text color to Red before printing
printf("\033[31m");
printf("VEXcode");