🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #41

Re: TNMUDP for Builder 3.0

#41
From: Mike Wahler
Date: Wed, 18 Oct 2000 00:00
66 lines
2772 bytes
Slawomir Stanek <staneks@kki.net.pl> wrote in message
news:8skr9l$art$1@news.tpi.pl...
> I have a problem.
> I send information from server to client. Protocol is UDP
> I trying read this packet by:
>
>   char *Buff;
>   Buff = new char[NumberBytes];
>   eSocket->ReadBuffer(Buff, NumberBytes, NumberBytes);
>   Memo1->Lines->Add("Message is:"+Buff);

No, that's an attempt to add two pointers, which is
not allowed.  If you want to concatenate 'C-style'
strings (arrays of char), you must either copy the
characters from one array to the end of the other
(and ensure the 'target' array is large enough), or
(much simpler) cast them to std::string, which does
have a version of operator+() that does concatenation.
Since your code indicates that the 'Add()' function takes
a char* argument, then you pass the return value of
the std::string's c_str() method, which is the correct
type.

Broken down:
std::string part1("Message is:");
std::string part2(Buff);
std::string msg = part1 + part2;
Memo1->Lines->Add(msg.c_str());

Or "all at once":

Memo1->Lines->Add((std::string("Message is:") +
std::string(Buff)).c_str() );

(not sure if all those parentheses are technically necessary,
I put them there to make sure of (and show the intended)
order of evaluation.)

To use the standard library class 'std::string',
#include <string>

If you can't or won't use the std::string type, let me know
and I'll show you how to do it the 'old fashioned' C way. :-)

-Mike
P.S. Note: the group named in your crosspost ( 'alt.lang.c++' )
is probably non-existent (my server doesn't have it, anyway).
You probably want 'comp.lang.c++'.

>
> and it doesn't work, because compiler error about pointer.
>
> I traing that:  Memo1->Lines->Add("Message is:"+(char)Buff);
> it's doesn't work too
>
> How I can conversion *Buff and show buffor in Memo1 (see above)
>
> Thanx for any suggestions.
> Slawomir Stanek
>
>
>
>
>
>
>
Technical Details
Message-ID: <8skv0b$ktg$1@nntp9.atl.mindspring.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <8skr9l$art$1@news.tpi.pl>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d4ba,31119448b3d2c47e
X-Google-Attributes: gid10d4ba,public
X-Google-Thread: 114592,31119448b3d2c47e
X-Google-Attributes: gid114592,public
From: "Mike Wahler" <mkwahler@mkwahler.net>
Subject: Re: TNMUDP for Builder 3.0
Date: 2000/10/18
Message-ID: <8skv0b$ktg$1@nntp9.atl.mindspring.net>
X-Deja-AN: 683024958
Content-Transfer-Encoding: 7bit
References: <8skr9l$art$1@news.tpi.pl>
Organization: MindSpring Enterprises
X-MSMail-Priority: Normal
X-Priority: 3
X-Server-Date: 18 Oct 2000 19:51:39 GMT
Content-Type: text/plain; charset="iso-8859-1"
Mime-Version: 1.0
Reply-To: "Mike Wahler" <mkwahler@ix.netcom.com>
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
Newsgroups: alt.comp.lang.learn.c-c++,att.lang.c++