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.
Post Reply
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

Post by Lotti »

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

Post by Ksmith22 »

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

Post by Lotti »

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

Post by toxicBunny »

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

Post by Lotti »

now works! thanks to all!
Post Reply