[英]using gotoxy positioning in a “for loop”
int strtnumber,endnumber,remainder,i;
gotoxy(2, 0);
printf("Enter Start value: "); //enters start number
cin >> strtnumber;
gotoxy(2, 1);
printf("Enter End Value: "); //enters end number
cin >> endnumber;
cout << "==================================================="<< endl;
for (; strtnumber <= endnumber; strtnumber++) {
remainder = strtnumber % 2;
if (remainder == 1) {
cout << strtnumber << endl;
}
if (remainder == 0) {
cout << strtnumber << endl;
}
}
我想使用gotoxy分隔奇數和偶數這是我想要實現的輸出:
ODD | EVEN
1 | 2
3 | 4
5 | 6
我想使用gotoxy分隔奇數和偶數這是我想要實現的輸出:
我使用過的幾乎所有系統都可以使用ansi終端。 甚至嵌入式系統也將(通過RS232)連接到VT100或同等產品。
PC隨附有ansi術語仿真器,或者可以輕松下載和安裝仿真器。
注意:提供的注釋很清楚,Ansi i / o不屬於C ++。
但是您可以輕松找到示例代碼來調用您可能想要的ansi終端功能。
這是我自己的類的有用部分,該類已經在Ubuntu的每個版本,多個Linux終端仿真器和vxWorks等上使用。我目前使用與Lubuntu一起安裝的仿真器。 尚未找到名稱,但幫助引用了Qt_io:
#include <iostream>
using std::cout, std::endl;
#include <string>
using std::string, std::to_string;
class Ansi_t // provide access to features of ansi-compatible terminal
{
public:
string clrscr (void)
{ return '\033' + string("[H") + '\033' + string("[2J"); }
// --v------v- C++ 2d array indexing is 0 based
string gotoRC(int r, int c) {
return ('\033' + string("[") +
to_string(r+1) + ';' + to_string(c+1) + 'H');
} // 0 ^ 0 ^
// 1,1 is top left of ansi screen
// tbr - add other ansi functions here
}; // class Ansi_t
// usage: declare an instance, Ansi_t ansi;
// invoke method: std::cout << ansi.clrscr() << std::endl;
// invoke method: std::cout << ansi.gotoRC() << std::endl;
// to specify a named escape sequence ^^^^^^^^
// Ubuntu gnome-terminal ansi term cursor locations are
// 1-based with origin 1,1 at top left corner
class Hello_t // demo executable
{
Ansi_t ansi; // declare an instance
public:
Hello_t() { cout << ansi.clrscr() << ansi.gotoRC(9, 18) << "Hello "; }
~Hello_t() { cout << " world!\n\n\n" << endl; }
int operator()() { cout << "C++"; return 0; } // functor entrance
};
int main(int , char* * ) { return (Hello_t()()); }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.