Κονσόλα#

Εισαγωγή#

Η κονσόλα VEXcode V5 εμφανίζεται στο παράθυρο Monitor μέσα στο VEXcode. Η έξοδος της κονσόλας μπορεί να εμφανίσει κείμενο, αριθμούς και τιμές μεταβλητών ενώ εκτελείται ένα έργο.

Όταν χρησιμοποιείτε τον κώδικα VS, η έξοδος της κονσόλας που βασίζεται σε κείμενο εμφανίζεται στο τερματικό αντί για την κονσόλα VEXcode.

Σημείωση: Όταν χρησιμοποιείτε την Κονσόλα VEXcode, πρέπει να συνδεθείτε στη Σειριακή Θύρα της Κονσόλας προτού εκτυπωθεί οποιαδήποτε έξοδος στην Κονσόλα.

Παρακάτω είναι μια λίστα με όλες τις λειτουργίες:

Ενέργεια — Έξοδος κειμένου.

  • printf — Displays text, numbers, or variable values in the Console or terminal.

Δράση#

printf#

printf displays text, numbers, or variable values in the Console. In VS Code, printf displays output in the terminal.

In C++, printf uses a format string. The format string is the text inside the quotation marks. It can include regular text, control sequences, and format specifiers that insert values from your project, like a score, timer, or sensor reading. See the String Formatting page for more information about format specifiers.

By default, printf does not automatically move to the next line. Add \n, which stands for a new line, when you want the next printed value to start on a new row.

Usage:
printf(value);

Παράμετρος

Τύπος

Περιγραφή

value

const char*

Το κείμενο, η συμβολοσειρά μορφοποίησης ή η ακολουθία ελέγχου που θα εμφανίζεται στην Κονσόλα ή στο τερματικό.

Επιστρέφεται τιμή:
Αυτή η συνάρτηση δεν επιστρέφει τιμή.

// Display a message in the Console
printf("Hello, robot!\n");

Η Κονσόλα VEXcode, που εμφανίζει την Κονσόλα και το κείμενο "Γεια σου, ρομπότ!".

// Display two messages on separate lines
printf("Hello, robot!\n");
printf("This prints on the next line.\n");

Η Κονσόλα VEXcode, που εμφανίζει την Κονσόλα και το κείμενο "Γεια σου, ρομπότ!" που εμφανίζεται στην πρώτη γραμμή και το "Αυτό εκτυπώνεται στην επόμενη γραμμή" στην γραμμή από κάτω.

// Display two messages on the same line
printf("Hello, ");
printf("robot!\n");

Η Κονσόλα VEXcode, που εμφανίζει την Κονσόλα και το κείμενο "Γεια σου, ρομπότ!".

// Display a number with two decimal places
printf("%.2f\n", 1.0 / 3.0);

Η κονσόλα VEXcode, που εμφανίζει την κονσόλα και το κείμενο "0.33" που εμφανίζεται.

Ακολουθίες ελέγχου#

Control sequences are short codes that can be printed with printf to change how text appears in the Console.

Control sequences are useful when you want to change text color or clear the Console directly inside a printf statement.

To change the text color, print \033 followed by a color code. At the start of a project, the Console text color is set to blue.

Χρώμα

Ακολουθία ελέγχου

Μαύρος

\033[30m

Κόκκινος

\033[31m

Πράσινος

\033[32m

Κίτρινος

\033[33m

Μπλε

\033[34m

Μωβ

\033[35m

Κυανό

\033[36m

Λευκό

\033[37m

Πορτοκάλι

\033[91m

Διαφανής

\033[97m

// Print text in different colors
printf("Default text color\n");
printf("\033[31m");
printf("Red text color\n");

Η Κονσόλα VEXcode, που εμφανίζει την Κονσόλα και μπλε κείμενο που λέει "Προεπιλεγμένο χρώμα κειμένου" που εμφανίζεται στην πρώτη γραμμή και κόκκινο "Κόκκινο χρώμα κειμένου" στη δεύτερη γραμμή.

Καθαρισμός της κονσόλας#

C++ does not have a separate Console function for clearing all rows. To clear the Console, print the control sequence \033[2J with printf.

Αυτό διαγράφει όλες τις γραμμές από την Κονσόλα και μετακινεί τον κέρσορα πίσω στη γραμμή 1.

// Clear the Console after two seconds
printf("VEXcode\n");
wait(2, seconds);
printf("\033[2J");