Mail Archives: djgpp/1999/08/17/20:22:00
In article <37B98244 DOT 226F207F AT americasm01 DOT nt DOT com>,
"Campbell, Rolf [SKY:1U32:EXCH]" <cp1v45 AT americasm01 DOT nt DOT com> wrote:
> John Clonts wrote:
>
> > > char THE_STRING [255];
> > > THE_STRING = "GOATS " + "MAKE " + "GOOD " + "PETS!";
> > > My compiler (DGJPP gccw32.exe) says: "invalid operands to binary
+"
> >
> > #include <string>
> > int main()
> > {
> > string theString = "GOATS " + "MAKE " + "GOOD " + "PETS!";
> > }
>
> Even though I've never used 'string' as a C++ datatype, and I did
not
> test your program, I really don't think this'll work. You're trying
to
> apply the '+' operator to 'char*'s. In C++, you can't over-ride that
> operator. I don't think you can override any pointer operators.
>
> You could do:
>
> string theString = "GOATS ";
> theString = theString + "MAKE " + "GOOD " + "PETS!";
>
Ok, good point, better is:
string theString = string("GOATS ") + "MAKE " + "GOOD " + "PETS!";
Cheers,
John
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
- Raw text -