Inserting a char into a string.

From: Connell Gauld (connell_at_freebreakfast.co.uk)
Date: 02/06/05


Date: Sun, 06 Feb 2005 21:41:33 +0000

Hey,
Sorry if this is a really stupid question - I'm new to C++.

I have a program like this:

std::string str;
...
...
...
char buffer[4];

The variable buffer has been filled with four characters.
How do I now make str equal to buffer?
ie I have "ABCD" in buffer and I would like "ABCD" in str.

Thanks
Connell



Relevant Pages

  • Re: <CR> into string
    ... I guess if you knew the buffer ... size you could do that in a loop that steps through the string. ... // user must guarantee buffer is at least 1 char longer than string, ... void strins ...
    (comp.lang.c)
  • Re: get number at end of string
    ... It doesn't modify 'str', use const. ... Prone to failure due to size of 'buffer'. ... beginning of that number and feed that pointer to atoi() directly. ... Your copying is faulty, it concats all digits and then parses the result ...
    (comp.lang.c)
  • Help with the ".times" command in ruby
    ... I'm trying to run a section of my ruby script 5000 times. ... print str} ... buffer = date_result.readlines ...
    (comp.lang.ruby)
  • Re: LPCTSTR and CString
    ... CString 'str' instance is built on the stack (it is a local ... its content (the string) is lost. ... If you really want a C interface, you should consider passing the buffer ...
    (microsoft.public.vc.mfc)
  • Re: LPCTSTR and CString
    ... CString 'str' instance is built on the stack (it is a local ... its content (the string) is lost. ... If you really want a C interface, you should consider passing the buffer ...
    (microsoft.public.vc.mfc)