[computer-go] C++: sstreams

Santi Ontañón santi at cc.gatech.edu
Wed Aug 9 12:08:15 PDT 2006


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/



More information about the computer-go mailing list