Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C++ Locate-like command

Posted on 1998-03-07
12
Medium Priority
?
351 Views
Last Modified: 2012-05-04
When I was programming in basic there was a locate command that let me put a character up on the screen in any location provided I supplied an x and y value.  How is this done in C++?
0
Comment
Question by:Booth882
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
  • +2
12 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1183210
C++ is platform/hardware independant.  The standard C and C++ libraries do not assume that you working on a console, that is a display, with rows and columns of letters.  There may be some libraries  available that will provide this sort of feature for a particular platform/hardware.

What compiler and what platform are you using?
0
 
LVL 6

Expert Comment

by:jpk041897
ID: 1183211
Only some examples for nietod's comment.

To achieve what you are looking for in UNIC console apps. you would use CURSES, in DOS Windows you woud use either the GDI OutText() function or a method for a specific window derived class, this method changes from VC++ to BC++, etc.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1183212
In windows you would use TextOut() (not OutText() (which prints backwards--just kidding)).  But there are lots of other details in windows!  (These details do not change from VC to BC, howwever, unless you are useing MFC or OWL.)  However, I doubt this is a windows program.  If it is a DOS program or a windows console program, then TextOut() isn't available.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Expert Comment

by:q2guo
ID: 1183213
Try the function
void gotoxy(int x, int y)
0
 
LVL 22

Expert Comment

by:nietod
ID: 1183214
gotoxy() is not part of the standard C++ library.  You might have a library that defines it, but Booth might not.
0
 
LVL 1

Author Comment

by:Booth882
ID: 1183215
I guess I should be more specific.  I am using Microsoft Visual C++ 4.0.  Windows at the moment is befuddling, so I am trying to stick with console applications until I figure out what I am doing.  If I were to use this void gotoxy(int x, int y) what should I include?  And what other things should I try?  Thank you all for your help, by the way.
0
 
LVL 1

Author Comment

by:Booth882
ID: 1183216
I guess I should be more specific.  I am using Microsoft Visual C++ 4.0.  Windows at the moment is befuddling, so I am trying to stick with console applications until I figure out what I am doing.  If I were to use this void gotoxy(int x, int y) what should I include?  And what other things should I try?  Thank you all for your help, by the way.
0
 
LVL 3

Expert Comment

by:q2guo
ID: 1183217
Sorry Booth882, function gotoxy() is not avaiable in
Visual C++.  It 's only avaible in Borland C.  To use
it you need to include <conio.h>
0
 
LVL 22

Expert Comment

by:nietod
ID: 1183218
In a windows console application you can use the SetConsoleCursorPosition() API function.
0
 
LVL 1

Author Comment

by:Booth882
ID: 1183219
how do I use SetConsoleCursorPosition and what do I include?  And what is API?
0
 
LVL 32

Accepted Solution

by:
jhance earned 400 total points
ID: 1183220
Here's an example of how to write a string to the screen:


#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <wincon.h>

void main(void)
{
      COORD coord;
      TCHAR *hello = "Hello World!";
      DWORD charsWritten;

      // Allocate a console buffer
      HANDLE hBuffer = CreateConsoleScreenBuffer(
            GENERIC_READ | GENERIC_WRITE,
            0,
            NULL,
            CONSOLE_TEXTMODE_BUFFER,
            NULL
      );
      if(hBuffer == INVALID_HANDLE_VALUE){
            fprintf(stderr, "ERROR in CreateConsoleScreenBuffer\n");
            exit(1);
      }

      if(!SetConsoleActiveScreenBuffer(hBuffer)){
            fprintf(stderr, "ERROR in SetConsoleActiveScreenBuffer\n");
            exit(1);
      }

      coord.X = 30;
      coord.Y = 12;
      if(!SetConsoleCursorPosition(hBuffer, coord)){
            fprintf(stderr, "ERROR in SetConsoleCursorPosition\n");
            exit(1);
      }

      if(!WriteConsole(hBuffer, hello, strlen(hello), &charsWritten, NULL)){
            fprintf(stderr, "ERROR in WriteConsole\n");
            exit(1);
      }

}
0
 
LVL 1

Author Comment

by:Booth882
ID: 1183221
You have my undying gratitude, jhance.

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question