[computer-go] C++: sstreams
Lars Nilsson
chamaeleon at gmail.com
Wed Aug 9 12:19:07 PDT 2006
std::ostringstream::str() returns std::basic_string<> for which
operator==() is defined. strcmp(s.str(), "...") on the other hand
yields compile error, as you'd have to use strcmp(s.str().c_str(),
"...") to get a pointer. All of this only make sense in the context of
C++ of course. Talking about C makes no sense once you're dealing with
std::ostringstream in the first place.
Lars Nilsson
On 8/9/06, Santi Ontañón <santi at cc.gatech.edu> wrote:
> even that won't work, in C/C++ you cannot compare strings directly
> (string is not a base type in C, so it does not have an == operator,
> if you use it, basically you are simply comparing the pointers), you
> need to use strcmp, so it'll be
>
> assert(strcmp(s.str(),"...")==0);
>
> On Aug 9, 2006, at 1:42 PM, Lars Nilsson wrote:
>
> > On 8/9/06, Peter Drake <drake at lclark.edu> wrote:
> >>
> >> I've followed the idiom and overloaded << so that I can print
> >> instances of
> >> my classes to any output stream. This much works fine:
> >>
> >> BitBoard b;
> >> b.clear();
> >> b.add(1);
> >> ostringstream s;
> >> s << b;
> >>
> >> Now, though, I want to compare s with a different string. The
> >> compiler won't
> >> accept this:
> >>
> >> assert(s == ".....\n.....\n.....\n.....\n.X...\n");
> >>
> >> Do I have to do something to convert s into a string?
> >
> > assert(s.str() == " ... ");
> >
> > Lars Nilsson
> > _______________________________________________
> > computer-go mailing list
> > computer-go at computer-go.org
> > http://www.computer-go.org/mailman/listinfo/computer-go/
>
> _______________________________________________
> computer-go mailing list
> computer-go at computer-go.org
> http://www.computer-go.org/mailman/listinfo/computer-go/
>
More information about the computer-go
mailing list