wxString -> how to convert a normal string into a wxStrin

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Lotti
Earned a small fee
Earned a small fee
Posts: 11
Joined: Thu Mar 23, 2006 4:32 pm

wxString -> how to convert a normal string into a wxStrin

Postby Lotti » Thu Mar 23, 2006 4:42 pm

hello to all! this is my first post and i'm on my first experience with wxWidgets libraries!

here's my problem: i need to change the Text of a label, using a normal string variable coming from another class. there's a way to convert a normal string to a wxString?

sorry from my poor english, i'm italian :) have a nice day!
[/code]

Ksmith22
I live to help wx-kind
I live to help wx-kind
Posts: 199
Joined: Mon Nov 21, 2005 4:34 pm

Postby Ksmith22 » Thu Mar 23, 2006 4:54 pm

Yeah, easily. Something like this will work:

Code: Select all

char* normalstr = "something";

wxString wxstr = normalstr;


Easy as that. You can use a normal string anywhere a wxString is required. The only thing you really can't do is the reverse - something like "normalstr = wxstr" (though "normalstr = wxstr.c_str()" should work).

Lotti
Earned a small fee
Earned a small fee
Posts: 11
Joined: Thu Mar 23, 2006 4:32 pm

Postby Lotti » Thu Mar 23, 2006 5:04 pm

i tried but this is what codeblocks gived to me:

error: conversion from 'std::string' to non-scalar type 'wxString' requested

toxicBunny
Super wx Problem Solver
Super wx Problem Solver
Posts: 424
Joined: Tue Jul 12, 2005 8:44 pm
Location: Alabama, USA

Postby toxicBunny » Thu Mar 23, 2006 6:06 pm

If you're talking about std::string, then try

Code: Select all

std::string myString = "something";
wxString wxstr = myString.c_str();


-Scott
wxMSW 2.6.2, VS 2002, 2003 and 2005, Code::Blocks and mingw, Windows XP Pro

Lotti
Earned a small fee
Earned a small fee
Posts: 11
Joined: Thu Mar 23, 2006 4:32 pm

Postby Lotti » Thu Mar 23, 2006 6:15 pm

now works! thanks to all!


Return to “wxCode”

Who is online

Users browsing this forum: No registered users and 2 guests