使用箭头符号打印圆圈

时间:2015-09-16 18:56:52

标签: c++ visual-studio-2013 geometry symbols

我一直在努力使用箭头符号以及delay();Sleep();绘制圆形图案,就像打印后一样,它会延迟大约几秒钟,然后打印{{ 1}}等等。这会给人一种绘图圈的印象。像

这样的东西

我尝试过到处搜索,到目前为止我发现的是如何只读取箭头键VM_KEYDOWN documentation。可悲的是,这不是我想要的。请帮忙? PS。我知道我还没有发布任何" Productive try"那是因为我没有这么做,所以不要生气:X 任何帮助将不胜感激。 :)

更新: 我尝试用这次失败的尝试打印箭头。

        ↑

   ←         →

        ↓

更新的-2 * 所以我设法用这个打印符号:

#include <iostream>
#include <string>
int main() { 
    std::wstring s(L"←→↑↓"); 
    std::wcout << s << "\n"; 
}

但现在我需要知道如何使用上面印刷的序列来做到这一点。

工作尝试

#include <iostream>
using namespace std;
int main()
{
  char left,right,up,down;

  up = 24;
  down = 25;
  left = 27;
  right = 26;

  cout << up;
  cout << down;
  cout << left;
  cout << right;
  cout << "\n";
  system("PAUSE");  
  return 0;
}

但这显然不准确/有效。

1 个答案:

答案 0 :(得分:1)

很高兴看到这种努力。我做了一些更改并添加了一个函数来将光标位置设置为您打印的同一行。试试这个:

    #include <iostream>
    #include <iomanip>
    #include <windows.h>
    #include <conio.h>
    using namespace std;
    HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD CursorPosition;
    void gotoXY(int, int);

    int main(){
    char left, right, up, down;
    up = 24;
    down = 25;
    left = 27;
    right = 26;
    cout << setw(20) << up<< endl << endl << endl<< setw(25);
    Sleep(1000);
    cout << right << endl<< endl<< endl << setw(20);
    Sleep(1000);
    cout << down;
    Sleep(1000);
    cout << endl;
    gotoXY(0, 2 + (1));
    cout << setw(15) << left<< endl;
    _getch();
    return 0;
   }
    void gotoXY(int x, int y)
    {
        CursorPosition.X = x;
        CursorPosition.Y = y;
        SetConsoleCursorPosition(console, CursorPosition);
    }
  

我承认它不是那么高效,但它有效,它应该有所帮助   你了解/更好地前进。