www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/08/17/20:22:00

From: johncc AT my-deja DOT com
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Catenation (spelled right?) of strings
Date: Tue, 17 Aug 1999 19:34:41 GMT
Organization: Deja.com - Share what you know. Learn what you don't.
Lines: 37
Message-ID: <7pcdgg$fqd$1@nnrp1.deja.com>
References: <37B36D0D DOT 7F00 AT lords DOT com> <37B8E3D3 DOT 516 AT my-deja DOT com> <37B98244 DOT 226F207F AT americasm01 DOT nt DOT com>
NNTP-Posting-Host: 204.254.32.135
X-Article-Creation-Date: Tue Aug 17 19:34:41 1999 GMT
X-Http-User-Agent: Mozilla/3.01Gold (Win95; I)
X-Http-Proxy: 1.0 x28.deja.com:80 (Squid/1.1.22) for client 204.254.32.135
X-MyDeja-Info: XMYDJUIDjohncc
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019