title: Resetting or Clearing Line in C++ Output
body: <p>I am trying to make a simple game. The basic concept is that the player (P) is moving around on a map. Eventually the player will have to avoid enemies and complete the level. Currently I have the player able to move around grab ammo and fire forward. I am clearing the entire screen and rewriting the map every so often so the user can input and play the game in real time. Here is my current code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;conio.h&gt;
  #include &lt;windows.h&gt;
  using namespace std;
  bool gameOver;
  const int width = 20;
  const int height = 20;
  int x, y, ammoX, ammoY, score;
  bool shot;
  enum eDirecton { STOP = 0, LEFT, RIGHT, UP, DOWN, ALL};
  eDirecton dir,shoot;
  void Setup()
  {
   gameOver = false;
   dir = STOP;
   x = width / 2;
   y = height / 2;
   ammoX = rand() % width;
   ammoY = rand() % height;
   score = 0;
  
  }
  void Draw()
  {
  system("cls"); //system("clear");
  for (int i = 0; i &lt; width+2; i++)
      cout &lt;&lt; "-";
  cout &lt;&lt; endl;
  
  for (int i = 0; i &lt; height; i++)
  {
      for (int j = 0; j &lt; width; j++)
      {
          if (j == 0)
              cout &lt;&lt; "|";
          if(shoot == UP){    
              if(i &lt; y &amp;&amp; j == x &amp;&amp; score &gt; 0){
                  cout &lt;&lt; ":";
                  shot = true;
              }
          }
          /*if(shoot == LEFT || shoot == ALL){    
              if(i == y &amp;&amp; j &lt; x &amp;&amp; score &gt; 0){
                  cout &lt;&lt; "~";
                  shot = true;
              }
          }
          if(shoot == RIGHT || shoot == ALL){
              if(i == y &amp;&amp; j &gt; x &amp;&amp; score &gt; 0){
                  cout &lt;&lt; "~";
                  shot = true;
              }
          }
          if(shoot == DOWN){
              if(i &gt; y &amp;&amp; j == x &amp;&amp; score &gt; 0){
                  cout &lt;&lt; ":";
                  shot = true;
              }
          }*/
          else if (i == y &amp;&amp; j == x)
              cout &lt;&lt; "P";
          else if (i == ammoY &amp;&amp; j == ammoX &amp;&amp; score &lt; 50)
              cout &lt;&lt; "A";
          else
          {
              bool print = false;
              /*for (int k = 0; k &lt; nTail; k++)
              {
                  if (tailX[k] == j &amp;&amp; tailY[k] == i)
                  {
                      cout &lt;&lt; "o";
                      print = true;
                  }
              }*/
              if (!print)
                  cout &lt;&lt; " ";
          }
  
  
          if (j == width - 1)
              cout &lt;&lt; "|";
      }
      cout &lt;&lt; endl;
  }
  
  for (int i = 0; i &lt; width+2; i++)
      cout &lt;&lt; "-";
  cout &lt;&lt; endl;
  cout &lt;&lt; "Score:" &lt;&lt; score &lt;&lt; endl;
  cout &lt;&lt; "x: " &lt;&lt; x &lt;&lt; endl;
  cout &lt;&lt; "y: " &lt;&lt; y &lt;&lt; endl;
  /*
  if(_kbhit()){
      cout &lt;&lt; _getch() &lt;&lt; endl;
  }//*/
  }
  
  void Input()
  {
  if (_kbhit())
  {
      switch (_getch())
      {
      case 75:
          dir = LEFT;
          break;
      case 77:
          dir = RIGHT;
          break;
      case 72:
          dir = UP;
          break;
      case 80:
          dir = DOWN;
          break;
      case 'w':
          shoot = UP;
          break;
      case 'a':
          shoot = LEFT;
          break;
      case 's':
          shoot = DOWN;
          break;
      case 'd':
          shoot = RIGHT;
          break;
      case 32:
          shoot = ALL;
          break;
      case 27:
          gameOver = true;
          break;
      }
  }
  }
  void Logic()
  {
  /*int prevX = tailX[0];
  int prevY = tailY[0];
  int prev2X, prev2Y;
  tailX[0] = x;
  tailY[0] = y;
  for (int i = 1; i &lt; nTail; i++)
  {
      prev2X = tailX[i];
      prev2Y = tailY[i];
      tailX[i] = prevX;
      tailY[i] = prevY;
      prevX = prev2X;
      prevY = prev2Y;
  }*/
  switch (dir)
  {
  case LEFT:
      x--;
      break;
  case RIGHT:
      x++;
      break;
  case UP:
      y--;
      break;
  case DOWN:
      y++;
      break;
  default:
      break;
  }
  
  if(x&gt;=width){
      x--;
  }
  else if(x &lt; 0){
      x++;
  }
  if(y&gt;=height){
      y--;
  }
  else if(y &lt; 0){
      y++;
  }
  //if (x &gt; width || x &lt; 0 || y &gt; height || y &lt; 0)
  //  gameOver = true;
  //if (x &gt;= width) x = 0; else if (x &lt; 0) x = width - 1;
  //if (y &gt;= height) y = 0; else if (y &lt; 0) y = height - 1;
  
  /* for (int i = 0; i &lt; nTail; i++)
      if (tailX[i] == x &amp;&amp; tailY[i] == y)
          gameOver = true;*/
  
  if (x == ammoX &amp;&amp; y == ammoY)
  {
      score += 10;
      ammoX = rand() % width;
      ammoY = rand() % height;
      //nTail++;
  }
  if(shot == true){
      score -= 10;
  }
  }
  int main()
  {
  Setup();
  while (!gameOver)
  {
      Draw();
      shoot = STOP;
      Input();
      Logic();
      shot = false;
      dir = STOP;
      Sleep(30); //sleep(10);
  }
  return 0;
  }
  </code></pre>
  
  <p>Is there a way to rewrite a certain line (such as the line the player is on and the one the player is moving to) so that I only have to rewrite a portion of the map instead of the entire map. It currently flashes and is hard to see since it flashes so often. If I could rewrite certain lines when the user inputs a key. I have tried \r and the setCursorPos() function, but I don't think I understand them entirely. I am using Windows 10 and Windows 7 and am using Microsoft Visual 2010. Please Help!
  Thanks</p>