Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8707571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:54:04+00:00 2026-06-13T03:54:04+00:00

ref:c++ example code at bottom from http://msdn.microsoft.com/en-us/library/windows/desktop/ms740120(v=vs.85).aspx I have a char array char RecvBuf[1024];

  • 0

ref:c++ example code at bottom from http://msdn.microsoft.com/en-us/library/windows/desktop/ms740120(v=vs.85).aspx
I have a char array

char RecvBuf[1024];

which gets filled up on receiving UDP message.
How do I store it in a std::string variable like string str; so that I can return a string from my function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:54:08+00:00Added an answer on June 13, 2026 at 3:54 am

    Use this constructor of std::string:

    string ( const char * s, size_t n );
    

    Basically, if RecvBuf is a standard (text) “string”, it’s OK just to make

    std::string str( RecvBuf );
    

    but this will copy all chars, until \0 is hit.


    And as this buffer stores raw bytes, received from a socket, you should expect \0 bytes.

    When you receive the data, you’ll know it’s size. So, just use

    std::string str( RecvBuff, buff_len );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to [MSDN: Array usage guidelines]( http://msdn.microsoft.com/en-us/library/k2604h5s(VS.71).aspx) : Array Valued Properties You should use
I am trying to add TCMPortMapper (http://code.google.com/p/tcmportmapper/) I have linked the framework in the
The example here http://mongoosejs.com/docs/populate.html Provides the following code var story1 = new Story({ title:
I'm trying to adapt the example here http://mongoosejs.com/docs/populate.html I have removed stories and am
In Xcode build ref: https://developer.apple.com/library/mac/#documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html#//apple_ref/doc/uid/TP40003931-CH3-SW45 It says: ACTION Description: Identifier. Identifies the type of
I suppose that this is an interesting code example. We have a class --
Reffering to Apple'S HIG on Menu, Using Symbols in Menu http://developer.apple.com/mac/library/DOCUMENTATION/UserExperience/Conceptual/AppleHIGuidelines/XHIGMenus/XHIGMenus.html#//apple_ref/doc/uid/TP30000356-TPXREF125 How do I
How can I hide ?ref string from users but pass it to php code
Suppose I have the following disposable class and example code to run it: public
I have this code, but it is not a practical example. Ex. class Animal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.