🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: alt.comp.lang.learn.c-c++
2 messages
2 total messages Started by Slawomir Stanek Wed, 18 Oct 2000 00:00
TNMUDP for Builder 3.0
#40
Author: Slawomir Stanek
Date: Wed, 18 Oct 2000 00:00
18 lines
1250 bytes
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);

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
Re: TNMUDP for Builder 3.0
#41
Author: 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
>
>
>
>
>
>
>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads