I know C and am trying to learn C++, can someone please tell me why the 
following program will not compile in Linux. I have tried using the 
following. Also, does gcc support the ansii C++ string class? If so, how do 
compile a program using it?

[paul@localhost paul]$ g++ test.cpp
test.cpp: In function `int main()':
test.cpp:25: `cout' undeclared (first use this function)
test.cpp:25: (Each undeclared identifier is reported only once for each 
function it appears in.)
test.cpp:25: `endl' undeclared (first use this function)
[paul@localhost paul]$



#include <iostream.h>

class CRectangle {
    int width, height;
  public:
    void set_values (int, int);
    int area (void) {return (width * height);}
};

void CRectangle::set_values (int a, int b) {
  width = a;
  height = b;
}

int main () {
  CRectangle a, *b, *c;
  CRectangle * d = new CRectangle[2];
  b= new CRectangle;
  c= &a;
  a.set_values (1,2);
  b->set_values (3,4);
  d->set_values (5,6);
  d[1].set_values (7,8);
  cout << "a area: " << a.area() << endl;
  cout << "*b area: " << b->area() << endl;
  cout << "*c area: " << c->area() << endl;
  cout << "d[0] area: " << d[0].area() << endl;
  cout << "d[1] area: " << d[1].area() << endl;
  return 0;
}


thanks,

Paul

Reply via email to