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

Recommended Answers

All 5 Replies

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().

Member Avatar for GreenDay2001

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

commented: Helps ~~SpS +3

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;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.