| re: missing zeroterminator in string.c_str()?
"klaus hoffmann" <dr.hoffmann.k@t-online.de> wrote...[color=blue]
> In the following program I would expect r to be a zero terminated string[/color]
of[color=blue]
> length 1. Am I wrong?[/color]
The program is not supposed to compile. 'string' is undefined.
Once you #include <string>, it works fine for me. 'y' is a string
of length 1, and it should only contain '1'. 'c_str()' for it
returns a string that contains '1' and '\0'.
[color=blue]
> The STL I'm using omit the zeroterm in this situation.[/color]
Chuck it. Get a decent implementation.
[color=blue]
> Klaus
>
> #include <iostream>
>
> using namespace std; //introduces namespace std
>
> int main(){
> string x("12");
> string::iterator p(x.begin()),q(x.begin()+1);
> string y(p,q);
> const char *r=y.c_str();
> cout <<r << " "<< int(r[0])<< " "<< int(r[1]);
> return 0;
> end;[/color]
"end;" ? What language is your native? :-)
Victor |