James Kanze
12/17/2008 1:30:00 PM
On Dec 17, 12:14 pm, thobiasvaka...@gmail.com wrote:
> On Dec 17, 2:17 pm, James Kanze <james.ka...@gmail.com> wrote:
> > On Dec 17, 7:11 am, thobiasvaka...@gmail.com wrote:
> > > I have a problem like this.
> > > How to handle \x0 character inside a string.
> > > Eg:-
> > > #include <string>
> > > #include <iostream>
> > > int main()
> > > {
> > > string str("abcdef\x0 xyz");
> > > cout << "length =" << str.length() << endl;
> > > cout << "string=" << str << endl;
> > > return 0;
> > > }
> > > The output of this program is as follows :
> > > length =6
> > > string=abcdef
> > > But I have to get the output as :
> > > abcdef xyz
> > Well, you have to count the characters, but:
> > string str( "abcdef\0 xyz", 11 ) ;
> > should work. Or if you don't want to count them:
> > static char const strInit[] = "abcdef\0 xyz" ;
> > string str( strInit, sizeof( strInit ) - 1 ) ;
> Thanks for your support. It's working fine. But actually my
> input data is of type string. So I can't use the first case.
> In the second case, I can't able to convert the string to a
> const char with \0.
If you're input data is of type std::string, then there's no
problem; it will already contain whatever it's supposed to
contain. And I don't understand the second sentence; you
obviously can't convert a string to a char const, since a string
contains more than one character. And that has nothing to do
with my second example.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34