need help creating a class in C++

piski

Senior member
Jan 21, 2002
312
0
0
I have created the file rect.h it contains the following code:

class Rectangle
{
public:
Rectangle();
void relativeSize(double factor);
void changeLength(double num);
void changeWidth(double num);
void showSides(string color);
double area();
double perimeter();
double getLength();
double getWidth();
private:
double length;
double width;
}

I am getting an error on the function void showSides(string color). It is saying that 'string' is an undeclared identifier..why?

second. I have created an implementation file as well called rect.cpp. My header statements are this:

#include <iostream>
#include "rect.h"

using namespace std;

is this the proper way to do that? It is telling me that there is a missing ; before 'using'..

thanks
k
 

piski

Senior member
Jan 21, 2002
312
0
0
okay i included the string header in my implementation file and is giving me an error:

rect.h(14) : error C2061: syntax error : identifier 'string'

what is this now?
thanks
K
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
Originally posted by: screw3d
Originally posted by: BingBongWongFooey
Originally posted by: screw3d
Originally posted by: PrincessGuard
Actually it's #include <string>

I think it depends on the compiler?
:eek:
So do you always just leave the .h out?

For standard c++ headers, yeah, there is no .h, but compilers still supply iostream.h and whatnot, for backwards compatability with pre-standard C++. But the standard is six years old. :)
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
also for c library headers like <string.h> <stdio.h>, you remove the .h and add a c in front of it eg <cstdlib> <cstdio> <cstring> etc