CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2006
    Posts
    16

    How To Convert Received Bytes To String?

    Hi friends, at an example i found in MSDN library, such a command is used to convert the received bytes to ASCII string;

    data = Text::Encoding::ASCII->GetString( bytes, 0, i );

    But my compiler can not build due to errors in this statement. I think this code is written for 2003 version and I use 2005, so there must be a new translating method just like many other changes... Can you help me about how to do this in version 2005. Thanks...
    Last edited by Noreturn; December 24th, 2006 at 06:35 PM.

  2. #2
    Join Date
    Jun 2006
    Location
    chennai
    Posts
    72

    Re: How To Convert Received Bytes To String?

    hi,
    what is the error message you get??
    bye
    P.Somasundaram

  3. #3
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: How To Convert Received Bytes To String?

    Simply assign those bytes to CString or std::string object. You can also create a buffer using new char[recvd_size] and use memcpy/strcpy to copy it.
    Regards,
    Ramkrishna Pawar

  4. #4
    Join Date
    Aug 2005
    Posts
    478

    Re: How To Convert Received Bytes To String?

    You have to be careful with the methods prescribed by Krishnaa, data is not be guaranteed to be null-terminated, nor or you guaranteed that your null-terminated string that you send will arrive in one piece.
    Windows XP, Visual Studio 2008, SVN

  5. #5
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: How To Convert Received Bytes To String?

    Quote Originally Posted by Calculator
    You have to be careful with the methods prescribed by Krishnaa, data is not be guaranteed to be null-terminated, nor or you guaranteed that your null-terminated string that you send will arrive in one piece.

    Yes, if sent data is not NULL terminated you must know the length of the string to pick up from the recvd data, Or you must send one string at a time on one connection and then some kind of delimiter to identify the end of one pack.
    Regards,
    Ramkrishna Pawar

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured