adding char into a string

From: Jason (jason.carney1_at_btinternet.com)
Date: 12/30/03


Date: Tue, 30 Dec 2003 06:58:34 +0000 (UTC)

Hi,

can clarify for me how to add a single char into a string. At the moment I
do this:

    str.insert((string::size_type) tileidx - 1, &ch);

and it corrupts str. If this is wrong perhaps somebody would be kind enough
to give me code for adding and removing a character from a string. I took
the following from josuttis book c++ standard template library, page 491,
for anyone that uses it:

s.insert((std::string::size_type)0, 1, ' ');

and changed it to the above, as it would not compile if the last argument is
not a pointer. I dont really want to insert single character strings into
my string if I can avoid it.

thanks for any help.

jason



Relevant Pages

  • Re: Convert VB code to C code.
    ... Use strtol() instead; it doesn't have this problem, ... meaning that the Basic code handles single characters. ... And since all members of the string are worth the same ... Unless you want a string instead of a single char, ...
    (comp.lang.c)
  • Re: help a beginner : code not working
    ... It contains a single char with ... It happens to contain a string of length 0. ... Presumably missing? ... drug-addicted gang member who had committed his first murder ...
    (comp.lang.c)
  • Re: WPF/LinqToSql/DataGrid
    ... String must be exactly one ... The only info I know how to get is the stack trace and it's not ... I think what happens is that you have a divergence between your LINQ ... contains strings that are longer than a single char. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Can I send char as array argument?
    ... Or create a separate function that takes a single char. ... > void main ... main returns int. ... to a string. ...
    (comp.lang.c)
  • Re: atoi question
    ... > My input is a string which holds a number on place 4. ... > string while I put a single char into it. ... want to convert a single character in the range '0' to '9' then ... the standard the rest of the character set has no such guarantee so, ...
    (comp.lang.c)