I have to write a class for a new "home-made" string class, and I do not know how to attack the operator>> . I will provide my class constructor and what i tried...

String::String( const char A[] )
{
   char X = A[0];
   int pos = 0;
   Length = 0;

   while (X!='\0')
   {
      Length++;
      pos++;
      X = A[pos];
   }
   Capacity = 16;
   while (Length > Capacity)
   {
      Capacity+=16;
   }
   Mem = new char[Capacity];
   for (unsigned I=0; I<Length; I++)
   {
      Mem[I] = A[I];
   }
}
istream& operator>>( istream& In, String& A )
{
   char X[128];

   In >> X;

   if(In.good())
   {
      A = X;
   }
   return In;
}

the simple thing I am trying to do is...

String C;

cin >> C;

>>cin << C;

wrong. should be cin >> C;

That was a typo...sorry i fixed it.

you didn't say if you have a problem with the >> operator or not. And if there is a problem, what is it? Looks like it should work to me.

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.