简体   繁体   English

在“ for循环”中使用gotoxy定位

[英]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;
        }

    }

I would like to separate the odd and even numbers using gotoxy This is the output I would like to achieve: 我想使用gotoxy分隔奇数和偶数这是我想要实现的输出:

         ODD    |   EVEN
          1     |     2
          3     |     4
          5     |     6

I would like to separate the odd and even numbers using gotoxy This is the output I would like to achieve: 我想使用gotoxy分隔奇数和偶数这是我想要实现的输出:

Almost every system with which I have worked has ansi terminal's available. 我使用过的几乎所有系统都可以使用ansi终端。 Even the embedded systems would be connected (via RS232) to VT100's or equivalent. 甚至嵌入式系统也将(通过RS232)连接到VT100或同等产品。

PC's come equipped with ansi term emulators, or the emulators can be trivially downloaded and installed. PC随附有ansi术语仿真器,或者可以轻松下载和安装仿真器。


Note: The comments provided are clear, Ansi i/o is not part of C++. 注意:提供的注释很清楚,Ansi i / o不属于C ++。

But you can easily find example code to invoke the ansi terminal functions you might want. 但是您可以轻松找到示例代码来调用您可能想要的ansi终端功能。

Here is a useful part of my own class which has worked on every version of Ubuntu Linux, and multiple Linux terminal emulators, and vxWorks, etc. I currently use an emulator installed with Lubuntu. 这是我自己的类的有用部分,该类已经在Ubuntu的每个版本,多个Linux终端仿真器和vxWorks等上使用。我目前使用与Lubuntu一起安装的仿真器。 Have not found the name, but the help references Qt_io: 尚未找到名称,但帮助引用了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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM