Using the conio library

Started by
6 comments, last by Surg AKA Kunark 19 years, 10 months ago
How come when I include the conio library, it does not allow me to use all the functions contained within the Library.

#include <iostream.h> //Used for console input output
#include <fstream.h> //Used for file input output 
#include <windows.h> //Needed to allow color for text
#include <lvp\string.h> //Allows the use of strings
#include <conio.h> //for getche() and other useful functions

//------Some other code -------

void GameMain(fstream &DataFile) {
		
	while ( GameArea != 0 ) {
		//Code to contain all the areas and gaming within GameMain
		//When Area is equal to Zero Game is over
		while ( GameArea == 1 ) {
			//Code to contain area within area one
			clrscr();
			gotoxy(0,0);
			cout << "Welcome " << MainPlayer.Name;
			cout << ", this is just a test for the main game area\n";
			gotoxy(0, 40);
			GameArea = 0;
		}
		
		while ( GameArea == 2 ) {
			//Code to contain area within area two

			GameArea = 0;
		}
		
		while ( GameArea == 3 ) {
			//Code to contain area within area three

			GameArea = 0;
		}
		
		while ( GameArea == 4 ) {
			//code to contain area within area four

			GameArea = 0;
		}
	}
}
I get the following two errors:
Quote: D:\Program Files\Microsoft Visual Studio\PROJECTS\Zephyr\Zephyr.cpp(99) : error C2065: 'clrscr' : undeclared identifier D:\Program Files\Microsoft Visual Studio\PROJECTS\Zephyr\Zephyr.cpp(147) : error C2065: 'gotoxy' : undeclared identifier
Thanx everyone, also thanks for the english lesson as well. I'll read those sites and try to figure this out. I guess the book I'm reading is old, cause that's what it teaches, lol. Again thanx for the help. [Edited by - Surg AKA Kunark on June 15, 2004 7:21:05 PM]
~~Johnathan~~LTM my new fad, know it, use it, love it, LAUGHING TO MYSELF
Advertisement
I'm pretty sure those functions are deprecated. Look at the win32 console functions instead.

Edit: how to perform a clear screen

Heres a pretty good link for you
Okay, umm two things... thanx for the quick response that was awesome. But you just made me feel dumb, what does deprecated mean. Also, where would i find the win32 console functions?

Do I make myself sound stupid? Cause I sure feel it. lol
~~Johnathan~~LTM my new fad, know it, use it, love it, LAUGHING TO MYSELF
Those are functions only available on the Borland (now, I think, Inprise) compilers. They're not depricated, but if they were, that simply means that they're outdated and no longer available (actually, most depricated things are still available, you just get a warning). You can actually find the code for those two functions on line, if you can't find them I'll help.
-~-The Cow of Darkness-~-
You can find the console functions here. Instead of gotoxy() you need to use SetConsoleCursorPosition(). Replacing clrscr() is a bit trickier; here's an MSKB article that explains how to do it.
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Bah my inet disconnected so I gotta re-write this out.. lol.

I got the clearscreen function working but I am still having troubles figuring out how to set the console cursor position with the SetConsoleCursorPosition() function. I checked the example on microsofts site but its alittle too complicated for me. Could anyone lay it out in laymens terms for me. An example perhaps. Would greatly appreciate it. Also I noticed a TextAttribute function on the one page... for changing text color in the console. Could someone maybe show me an example how to use that. It may be better than what I am already using. Thanx again for all your help.
~~Johnathan~~LTM my new fad, know it, use it, love it, LAUGHING TO MYSELF
For SetConsoleCursorPosition(), you just need to pass in a handle to the console, and a COORD structure which contains the new coordinates. Example:
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);COORD cursorPos = {10, 10};SetConsoleCursorPosition(console, cursorPos);std::cout << "Hello from 10,10" << std::endl;


For SetConsoleTextAttribute(), you pass in a handle to the console and one or more constants, OR's together:
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleTextAttribute(console, FOREGROUND_RED);std::cout << "Red text!" << std::endl;SetConsoleTextAttribute(console, FOREGROUND_BLUE);std::cout << "Blue text!" << std::endl;SetConsoleTextAttribute(console, FOREGROUND_GREEN | BACKGROUND_RED);std::cout << "Green on red text!" << std::endl;SetConsoleTextAttribute(console, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);std::cout << "Normal text" << std::endl;
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Thanx for the help. I should be able to figure this out now.

I am assuming that the top left hand corner is {0,0} For X,Y coordinates.

Okay so I figured out that is right. Now here is what I have.

void GameMain(fstream &DataFile, COORD &CursorPos) {			while ( GameArea != 0 ) {		//Code to contain all the areas and gaming within GameMain		//When Area is equal to Zero Game is over		while ( GameArea == 1 ) {			//Code to contain area within area one			system("cls");			SetConsoleCursorPosition(Console, CursorPos);			cout << "Welcome " << MainPlayer.Name;			cout << ", this is just a test for the main game area\n";			CursorPos.X = 0;			CursorPos.Y = 10;			SetConsoleCursorPosition(Console, CursorPos);			cout << "To tell where what is what\n";			GameArea = 0;		}				while ( GameArea == 2 ) {			//Code to contain area within area two			GameArea = 0;		}				while ( GameArea == 3 ) {			//Code to contain area within area three			GameArea = 0;		}				while ( GameArea == 4 ) {			//code to contain area within area four			GameArea = 0;		}	}}


But, instead of making 10 spaces between the first line and the second. It places the first line at the x,y coordinates of 0,10. Would you need to declare a new COORD variable for each. That would seem to make it take up alot of useless space.
~~Johnathan~~LTM my new fad, know it, use it, love it, LAUGHING TO MYSELF

This topic is closed to new replies.

Advertisement