CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2006
    Location
    beyond the pillars of hercules
    Posts
    295

    [RESOLVED] std string question

    im not really familiar with the string class and i came across a "problem" on my code

    how is it possible to copy an array of bytes (binary) from a char array to a string variable?
    the char array holds the data of a file , when i try to copy to a string it only copies until the first null byte

  2. #2
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,725

    Re: std string question

    Code:
    string s;
    char   buffer[256]; // whatever
    
    s.assign(buffer,n);  // n = number of bytes to copy

  3. #3
    Join Date
    May 2006
    Location
    beyond the pillars of hercules
    Posts
    295

    Re: std string question

    thank you Philip Nicoletti!

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: std string question

    Quote Originally Posted by Cpp_Noob View Post
    thank you Philip Nicoletti!
    If you want to construct a string like this:
    Code:
    char buffer[1000];
    //...
    std::string s(buffer, 1000);
    Regards,

    Paul McKenzie

  5. #5
    Join Date
    May 2006
    Location
    beyond the pillars of hercules
    Posts
    295

    Re: [RESOLVED] std string question

    thanks, im still new to the string class

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