Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用光标操作C+打印垂直直方图+;[课程][已解决,无课程]_C++_Loops_Cursor_Ncurses - Fatal编程技术网

C++ 使用光标操作C+打印垂直直方图+;[课程][已解决,无课程]

C++ 使用光标操作C+打印垂直直方图+;[课程][已解决,无课程],c++,loops,cursor,ncurses,C++,Loops,Cursor,Ncurses,我以前问过这样的问题,但这有点误导,因为我没有包括印刷顺序。因为我了解了整个概念的变化,所以我认为再问一次会更贴切 而且它必须完全按照这个顺序进行。每一列的打印也必须用一个单独的功能来完成 第一个循环: * * 第二个循环: * * * * * 最后一个循环: * * * * * * *编辑:*显然,还有一种解决方案可以在不使用任何光标操作的情况下执行此操作。我的老师建议我首先将字符存储在字符指针中,然后逐行打印该字符指针内存。这很好。你不能按

我以前问过这样的问题,但这有点误导,因为我没有包括印刷顺序。因为我了解了整个概念的变化,所以我认为再问一次会更贴切

而且它必须完全按照这个顺序进行。每一列的打印也必须用一个单独的功能来完成

第一个循环:

*

*
第二个循环:

    *

*   *

*   *
最后一个循环:

    *

*   *

*   *   *

*编辑:*显然,还有一种解决方案可以在不使用任何光标操作的情况下执行此操作。我的老师建议我首先将字符存储在字符指针中,然后逐行打印该字符指针内存。这很好。

你不能按照你想要的方式执行此操作。您需要一次打印一条水平线,因为您不能垂直地输出到控制台

因此,首先您需要找出总共需要多少行,
totalines
,这是最大值
a
b
,和
c
。然后您应该迭代这些行中的每一行


在行迭代中,您需要在正确的位置打印出正确数量的
*
s。是否需要为
a
绘制点的条件是
a>=totalLines-line
(其中
line
是当前行,第一行从0开始)。类似地,对于
b
c
,您需要3个带有这些条件的
if
语句,每个语句都打印出空格或
*

这是一个诅咒程序

#include <iostream>
#include <curses.h>

using namespace std;

int main(int argc, char** argv)
{
  int a,b,c,i;
  cin >> a >> b >> c;

  initscr(); // initialise curses
  int rows, cols;
  getmaxyx(stdscr, rows, cols);  // get screen size


  for (i=0; i<a; i++) {
    mvprintw(rows - 1 - i, 0, "*"); // plot at bottom column 0
  }

  for (i=0; i<b; i++) {
    mvprintw(rows - 1 - i, 1, "*"); // plot at bottom column 1
  }

  for (i=0; i<c; i++) {
    mvprintw(rows - 1 - i, 2, "*"); // plot at bottom column 2
  }

  refresh();  // update screen
  getch(); // exit when key is pressed
  endwin(); // exit curses
  return 0;
}
#包括
#包括
使用名称空间std;
int main(int argc,字符**argv)
{
INTA、b、c、i;
cin>>a>>b>>c;
initscr();//初始化诅咒
int行,cols;
getmaxyx(stdscr,rows,cols);//获取屏幕大小

对于(i=0;i没有“光标”在标准C++中,只有一个不透明的输出流。你必须重新思考所有的事情。这就是为什么我需要用NCRESS或是做同样的事情来做的。有什么帮助吗?是的,你可以用NC咒ES来做。通过教程来做,你应该能够马上做到这一点。即使是有NRCUCE或类似的东西,也可以一行一行地做。根本帮不了我。我抽象了我的实际程序,其中包含一些复杂的绘图算法,由多个形状组成,而不仅仅是“*”。因此,我恐怕要么要处理光标操作,要么要更改整个程序本身:@user2362377是的,你可以用ncurses处理。你的问题似乎暗示你想用标准i/O库处理。Rite,ty。我编辑了标题。如果你知道如何用ncurses处理,请毫不犹豫地发布答案:>
    *

*   *

*   *
    *

*   *

*   *   *
#include <iostream>
#include <curses.h>

using namespace std;

int main(int argc, char** argv)
{
  int a,b,c,i;
  cin >> a >> b >> c;

  initscr(); // initialise curses
  int rows, cols;
  getmaxyx(stdscr, rows, cols);  // get screen size


  for (i=0; i<a; i++) {
    mvprintw(rows - 1 - i, 0, "*"); // plot at bottom column 0
  }

  for (i=0; i<b; i++) {
    mvprintw(rows - 1 - i, 1, "*"); // plot at bottom column 1
  }

  for (i=0; i<c; i++) {
    mvprintw(rows - 1 - i, 2, "*"); // plot at bottom column 2
  }

  refresh();  // update screen
  getch(); // exit when key is pressed
  endwin(); // exit curses
  return 0;
}