Thread: [Dev-C++] Converting char* to wxString
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Luis B. <lf...@ya...> - 2007-08-09 17:03:34
|
Can someone help me?=0A=0AI'm trying to convert a char* to a wxString:=0A=
=0Avoid wxOpengl3D::ReadFile(wxString & file)=0A{=0A=0A char * temp=3Dne=
w char[file.Len()+1];=0A CTextFile cfile;=0A wxString centerx;=0A=0A =
// Open file=0A cfile.InitializeWith((char *)file.mb_str( wxConvUTF8 =
));=0A cfile.OpenFileToRead();=0A=0A // Get a string from file ending=
in ';'=0A temp=3Dstrupr(cfile.get_str(temp,';'));=0A centerx=3Dtemp;=
=0A (...)=0A}=0A=0AI get this error:=0A=0Aerror: ambiguous overload for =
'operator=3D' in '((wxOpengl3D*)this)->wxOpengl3D::centerx =3D temp'=0AC:/w=
xWidgets-2.8.4/include/wx/string.h:676: note: candidates are: wxString& wxS=
tring::operator=3D(int) <near match>=0AC:/wxWidgets-2.8.4/include/wx/string=
.h:957: note: wxString& wxString::operator=3D(wxChar) <near=
match>=0AC:/wxWidgets-2.8.4/include/wx/string.h:971: note: =
wxString& wxString::operator=3D(const wxWCharBuffer&) <near match>=0AC:/wx=
Widgets-2.8.4/include/wx/string.h:1026: note: wxString& wxS=
tring::operator=3D(const wxString&) <near match>=0A=0AWhen using wxWidgets-=
2.6 no error were found.=0A=0AThanks in advance.=0A=0A=0A=0A=0A=0A =
=0A________________________________________________________________________=
____________=0ABe a better Heartthrob. Get better relationship answers from=
someone who knows. Yahoo! Answers - Check it out. =0Ahttp://answers.yahoo.=
com/dir/?link=3Dlist&sid=3D396545433 |
|
From: matheus r. <mfr...@gm...> - 2007-08-09 17:22:19
|
Change function declaration to:
void wxOpengl3D::ReadFile(const wxString & file)
maybe it helps compiler find the exact match.
2007/8/9, Luis Bras <lf...@ya...>:
>
> Can someone help me?
>
> I'm trying to convert a char* to a wxString:
>
> void wxOpengl3D::ReadFile(wxString & file)
> {
>
> char * temp=new char[file.Len()+1];
> CTextFile cfile;
> wxString centerx;
>
> // Open file
> cfile.InitializeWith((char *)file.mb_str( wxConvUTF8 ));
> cfile.OpenFileToRead();
>
> // Get a string from file ending in ';'
> temp=strupr(cfile.get_str(temp,';'));
> centerx=temp;
> (...)
> }
>
> I get this error:
>
> error: ambiguous overload for 'operator=' in
> '((wxOpengl3D*)this)->wxOpengl3D::centerx = temp'
> C:/wxWidgets-2.8.4/include/wx/string.h:676: note: candidates are: wxString&
> wxString::operator=(int) <near match>
> C:/wxWidgets-2.8.4/include/wx/string.h:957: note: wxString&
> wxString::operator=(wxChar) <near match>
> C:/wxWidgets-2.8.4/include/wx/string.h:971: note: wxString&
> wxString::operator=(const wxWCharBuffer&) <near match>
> C:/wxWidgets-2.8.4/include/wx/string.h:1026: note: wxString&
> wxString::operator=(const wxString&) <near match>
>
> When using wxWidgets-2.6 no error were found.
>
> Thanks in advance.
>
>
>
> ________________________________
> Got a little couch potato?
> Check out fun summer activities for kids.
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems? Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE:
> http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
|
|
From: Lloyd <ll...@cd...> - 2007-08-10 04:11:54
|
On Thu, 2007-08-09 at 10:03 -0700, Luis Bras wrote: > centerx=temp; I think here is the error. centerx is a wxString and temp is char* and they are incompatible data types. So if you want to assign temp to centerx do the following centerx=wxString::FromAscii(tempx); [static wxString FromAscii(const char* s)] Regards, Lloyd ______________________________________ Scanned and protected by Email scanner |
|
From: Stefan K. <Klu...@gm...> - 2007-08-10 07:10:24
|
Lloyd schrieb: > On Thu, 2007-08-09 at 10:03 -0700, Luis Bras wrote: > >> centerx=temp; >> > > I think here is the error. centerx is a wxString and temp is char* and > they are incompatible data types. So if you want to assign temp to > centerx do the following > > > centerx=wxString::FromAscii(tempx); > > [static wxString FromAscii(const char* s)] > > Regards, > Lloyd > Hi, this only works if you are really using ASCII (no characters above 127) and no locale based conversion is applied. (see http://www.wxwidgets.org/manuals/stable/wx_wxstring.html#wxstringfromascii ) To do this assignment with locale based conversion use something like: centerx=wxString(tempx,wxConvCurrent); (see http://www.wxwidgets.org/manuals/stable/wx_mbconvclasses.html#wxmbconvobjects ) The question is, why aren't you staying in wxWidgets space and use wxTextFile instead of CTextFile. This way you wouldn't have to worry about string format conversions. Also be careful with the line cfile.InitializeWith((char *)file.mb_str( wxConvUTF8 )); Are you sure that every Operating System running your software saves its filenames in UTF8? Probably the conversion should be file.mb_str( wxConvFileName ); Regards, Stefan |