I know these functions in C, but in C++ they doesn't work.
What is replacement for these functions in C++ ?
Thanks.

Recommended Answers

All 11 Replies

Hate to tell you this, but they don't exist in C either.

Chris

wherex, wherey, gotoxy are all Borland extensions. (Do Borland compilers still support them?) You can learn how to do it using the OS functions directly yourself.

Oh yes its Borland extensions :)
I dont understand this : "You can learn how to do it using the OS functions directly yourself. "

Well, Borland doesn't do it through magic, so there is a way to do it without their functions. For instance, if you are on Windows you would use SetConsoleCursorPosition instead of gotoxy, GetConsoleScreenBufferInfo instead of wherex and wherey, and SetConsoleTextAttribute instead of whatever you would use to set the color. Let me know if you need more info.

Ok, thanks!!

And your program will need to include windows.h header file.

Can someone tell me extansion in Visual C for wherex() and wherey() is?
I know to do that at Borlands but not in Visual.. :\
Tnx :twisted:

You can find the functions you need here -> Windows Console Functions

Here, I wrapped them for you:

#include <windows.h>
#include <iostream>

void gotoxy(int x, int y)
{
    COORD pos = { x, y };

    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

int wherex()
{
    CONSOLE_SCREEN_BUFFER_INFO csbi;

    GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);

    return csbi.dwCursorPosition.X;
}

int wherey()
{
    CONSOLE_SCREEN_BUFFER_INFO csbi;

    GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);

    return csbi.dwCursorPosition.Y;
}

int main()
{
    gotoxy(30, 10);

    std::cout << "Hello, World!";

    int x = wherex();
    int y = wherey();

    gotoxy(0, 0);

    std::cout << "end pos of \"Hello, World!\" = ";
    std::cout << "(" << x << ", " << y << ")" << std::endl;

    std::cin.get();
}

WoW, it isn`t like we learn in school.. :O
But, tnx for reply...
^____^

WoW, it isn`t like we learn in school.. :O
But, tnx for reply...
^____^

That's because your school teaches 20-year-old techniques on 20-year-old software. They don't bother teaching today's C/C++.

They don't bother teaching today's C/C++.

That's not even today's C++. If they tried to teach today's C++, the teachers stuck in 1990 would have a stroke.

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.