hello friend, i am a new programmer, i have probem use gotoxy in visual c++, help me please :cheesy:

MS-Windows, use these console functions. First, get the handle to the consol window with GetConsoleWindow() then move the cursor to desired location with SetConsoleCursorPosition().

I also discovered the same problem in MSVC2005 express. Also i saw no clrscr(); .

Is there any subsitute for clrscr(); too.

Ah, the old Turbo C bad habit clrscr() function. First try to make your program without it, it is rarely needed! You can replace one bad habit with another and use:

#include <stdlib.h> 

void clrscr(void)
{
  system ("cls");
  //system ("clear"); // for Unix
}

A more official version of a clrscr() function using Windows API is at:
http://www.daniweb.com/code/snippet232.html

Comments
Helps ~~SpS

hello friend, i am a new programmer, i have probem use gotoxy in visual c++, help me please :cheesy:

Hmm, another Turbo C hold-over! You can replace it with the SetPixel() function from the Windows GDI32.lib. Vegaseat had plowed those fields long ago, and there is an example he left in the code snippets. Old C++ code, but should still work:

// plot a sinewave to the console window (cmd window)
// link with GDI32.lib or using Dev-C++ link libgdi32.a via
// Project>>Project Options>>Parameters>>Add Lib>>libgdi32.a
// this is a Windows Console Application   vegaseat  06mar2005
 
#include <cstdio>
#include <cmath>
#include <windows.h>
 
int main(void)
{
  int x, y;
  COLORREF yellow = RGB(255,255,0);
  COLORREF lightblue = RGB(173,216,230);
  
  // make sure the names match
  SetConsoleTitle("ConGraphics");
  HWND hWnd = FindWindow(NULL, "ConGraphics");
 
  HDC hDC = GetDC(hWnd);
  
  // draw a yellow sine curve
  for(x = 0; x < 700; x++)
  {
    // center at y = 200 pixels
    y = (int)(sin(x/100.0)*100 + 200);
    SetPixel(hDC, x, y, yellow);
  }
    
  // draw center line
  for(x = 0; x < 700; x++)
  {
    SetPixel(hDC, x, 200, lightblue);
  }
  
  ReleaseDC(hWnd, hDC);
  DeleteDC(hDC);
 
  getchar();  // wait
  return 0;
}
This article has been dead for over six months. Start a new discussion instead.