Hard Light Productions Forums
Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: untouchable on April 20, 2003, 08:51:25 pm
-
I've been learning how to write C++ code and I was testing some of the functions in the conio.h header file. I wrote this code to test the textcolor() function but it won't compile.
Code:
#include
#include
int main()
{
int i = 0;
while(!i)
{
textcolor(15);
cout << "\nTest\n";
cin >> i;
}
return 0;
}
Error:
[Linker error] undefined reference to `textcolor'
I would appreciate it if someone who had expiereince in writing C++ could help me out.
-
*bump*
-
Probably want to check in a programmers forum.
Buuuuuuuuutttttt......
check your spelling
check your text to make sure that the referenced command is in the included header files
so forth and so on
btw
How advanced are you?
My backwoods college didn't teach bupkis about including other .h files beside iostream and math and we really didn't learn all that much about math.h, suppose that's what I get for attending a community college in North Alabama. The average tech level for the surrounding environs is about 35% of what you'd expect in a what is essentially a running rural suburb from Gadsden, AL to Huntsville, AL.
-
This is probably the most advanced thing that I have programmed so far... and its not very advanced yet but I've only been programming for about 2 weeks now.
typedef unsigned long int ULONG;
typedef unsigned short int USHORT;
#include
enum BOOL { FALSE , TRUE };
enum CHOICE { DrawRect = 1 , GetDims , GetArea , GetPerim,
ChangeDims , Quit };
class Rectangle
{
public:
//Rectangle Constructor
Rectangle( USHORT width , USHORT height );
//Rectangle Deconstructor
~Rectangle();
//accessors
void setSize( USHORT newWidth , USHORT newHeight );
USHORT getHeight() const { return itsHeight; }
USHORT getWidth() const { return itsWidth; }
ULONG getArea() const { return itsWidth * itsHeight; }
ULONG getPerim() const { return 2*itsWidth + 2*itsHeight; }
private:
USHORT itsWidth;
USHORT itsHeight;
};
//Rectangle Constructor
Rectangle::Rectangle( USHORT width , USHORT height )
{
itsWidth = width;
itsHeight = height;
}
//Rectangle Deconstructor
Rectangle::~Rectangle() {}
//Set the rectangle's size
void Rectangle::setSize( USHORT newWidth , USHORT newHeight )
{
itsWidth = newWidth;
itsHeight = newHeight;
}
USHORT menu();
void doGetArea( Rectangle );
void doGetPerim( Rectangle );
void doDrawRect( Rectangle );
void doGetDims( Rectangle );
int main()
{
Rectangle theRect(10,10);
USHORT choice = DrawRect;
USHORT qQuit = FALSE;
USHORT newHeight, newWidth;
//Loop
while (!qQuit)//While Quit is not true (or not equal to 1)
{
choice = menu();//Call the menu function
if (choice < DrawRect || choice > Quit)//Check to see if choice
//is valid
{
cout << "\nInvalid Choice, please try again.\n\n";
continue;
}
switch( choice )//Menu choices, default set to exit
{
case DrawRect:
doDrawRect(theRect);
break;
case GetDims:
doGetDims(theRect);
break;
case GetArea:
doGetArea(theRect);
break;
case GetPerim:
doGetPerim(theRect);
break;
case ChangeDims:
cout << "\nEnter new height: ";
cin >> newHeight;
cout << "\nEnter new width: ";
cin >> newWidth;
theRect.setSize( newWidth , newHeight );
cout << "\n";
break;
case Quit:
qQuit = TRUE;
break;
default:
cout << "Error in choice!\n";
qQuit = TRUE;
break;
}//End switch
}// End loop
}// End main
//Menu
USHORT menu()
{
USHORT choice;
cout << "--- Menu --- \n";
cout << "(1) Draw Rectangle\n";
cout << "(2) Dimensions\n";
cout << "(3) Area\n";
cout << "(4) Perimeter\n";
cout << "(5) Resize\n";
cout << "(6) Quit\n";
cout << "\nChoice: ";
cin >> choice;
return choice;
}
//Draw the rectangle
void doDrawRect( Rectangle theRect )
{
USHORT width = theRect.getWidth(); //Get rectangle width
USHORT height = theRect.getHeight(); //Get rectangle height
cout << "\n\n";
for( USHORT i = 0; i < height; i++ )
{
for( USHORT j = 0; j < width; j++ )
cout <<"*"; //draw *s until j is equal to the width
cout <<"\n"; //draw another row of *s until i is equal to the height
}
cout << "\n\n";
}
//Get and output the area of the rectangle
void doGetArea( Rectangle theRect )
{
ULONG area = theRect.getArea();
cout << "\nArea: " << area << "\n\n";
}
//Get and output the perimeter of the rectangle
void doGetPerim( Rectangle theRect )
{
ULONG perim = theRect.getPerim();
cout << "\nPerimeter: " << perim << "\n\n";
}
//Get and output the dimensions of the rectangle
void doGetDims( Rectangle theRect )
{
USHORT width = theRect.getWidth();
USHORT height = theRect.getHeight();
cout << "\nDimensions: ";
cout << "\nWidth: " << width;
cout << "\nHeight: " << height << "\n\n";
}
-
Code tags are your friends! :p
-
Originally posted by untouchable
I've been learning how to write C++ code and I was testing some of the functions in the conio.h header file. I wrote this code to test the textcolor() function but it won't compile.
Code:
#include
#include
int main()
{
int i = 0;
while(!i)
{
textcolor(15);
cout << "\nTest\n";
cin >> i;
}
return 0;
}
Error:
[Linker error] undefined reference to `textcolor'
I would appreciate it if someone who had expiereince in writing C++ could help me out.
If I remember right, textcolor() is not a standard function of conio.h. Are you sure that the conio.h you're using even has it? Atleast DJGPP has it, but I'm not sure about other compilers.
-
I examined the conio.h file and it included the function void textcolor(int color) and in the conio.c file was included the function definition:
void
textcolor (int color)
{
__FOREGROUND = color;
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
color + (__BACKGROUND << 4));
}
-
Ok... got it. I had to include the conio.c file as well as the header file for conio:
#include "conio.c"
-
If you need programming tutorials, then I would highly advice you to visit this website: GameTutorials (http://www.gametutorials.com). You will find there dozens of C/C++/OpenGL/SDL/DirectX tuts for beginners and experts fellows. I have learnt a lot studying them ;)