What's the correct way to compare two wxStrings? I tried Googling for an
answer but couldn't find anything.
Daniel.
or
str1.Cmp(str2) == 0
or
str1.CmpNoCase(str2) == 0
Eran
Really? You can tell I'm new to C++. Unless I'm confused, in C that
wouldn't work. I've been assuming that C++ strings would resemble C
strings and that wxString is some special wrapper and that I have to use
special methods to work on them.
Is wxString just the same as a regular C++ string then? If so, why do we
need wxString?
> or
>
> str1.Cmp(str2) == 0
>
> or
>
> str1.CmpNoCase(str2) == 0
Thanks.
Daniel.
-----Original Message-----
>From: Daniel Carrera <dcar...@gmail.com>
>Sent: Jan 19, 2010 11:17 AM
>To: wx-u...@googlegroups.com
>Subject: Re: How do you compare two wxString's?
>
>Eran Ifrah wrote:
>> str1 == str2
>
>Really? You can tell I'm new to C++. Unless I'm confused, in C that
>wouldn't work. I've been assuming that C++ strings would resemble C
>strings and that wxString is some special wrapper and that I have to use
>special methods to work on them.
>
>Is wxString just the same as a regular C++ string then? If so, why do we
>need wxString?
Define "regular C++ string", please.
Thank you.
There isn't an agreed definition on what a normal C++ string is? I would
have thought that std::string would be it. But I'm new at C++ so I might
be missing something fundamental.
Daniel.
http://docs.wxwidgets.org/stable/wx_wxstringoverview.html
Cheers,
Daniel.
-----Original Message-----
>From: Daniel Carrera <dcar...@gmail.com>
>Sent: Jan 19, 2010 9:06 AM
>To: wx-u...@googlegroups.com
>Subject: Re: How do you compare two wxString's?
>
And what it will be on platforms where std::string/STL is _not_ available?
That's why wxWidgets can be configured to not use STL and use it's own
implementation.
But that is only one part of it....
Thank you.
>
>Daniel.
No that wouldn't work in C. This is one of the big advantages of C++.
What happens is that the wxString class overrides the == operator. s1 ==
s2 is functionally equivalent to calling:
s1.operator ==(s2)
When you do this you are really calling a function something like this:
wxString& operator == (const wxString& source)
{
code to perform the comparison here...
return(*this);
}
Les
Indeed. I can see how that C++ has a lot more merit than I thought. I've
always avoided learning C++ because I keep hearing about how complicated
it is and how it is a huge language and so on.
But I can see that for my own work I can ignore 99% of the complexity of
C++ and just pick the bits and pieces that would make C more fun to use.
Cheers,
Daniel.
This is actually the preferred way to proceed to C++ if you already know
C. Always do 90% of your coding using what you already know, and pick up
new features in the remaining 10%. This does mean, in the beginning,
that you'll be using C++ as merely a "better C," but this is quite all
right. You can always add more features when you get more experience
under your belt. :-)
/Brian
> And what it will be on platforms where std::string/STL is _not_ available?
Isn't std::string a required part of any standards-compliant C++ platform?
The STL was adopted as part of the ANSI standard language quite some time
ago, so platforms that lack it are either quite old or non-compliant.