0

in my project I try to use the following line to get a string value:

string azonosito=ItemID->GetLabelText().c_str(); 

but it doesn't work, and this doesn't either:

string tipus=CategoryFilter->GetString(CategoryFilter->GetCurrentSelection()).c_str(); 

error: conversion from 'wxCStrData' to non-scalar type 'std::string {aka std::basic_string}' requested

I'm using Code::Blocks 13.12 and wxWidgets TDM 4.8.1., but this Code::Blocks can fully execute a project that was written in older wxWidgets version, with a totally same conversion method. What could be the problem?

Any comments and tips are welcome, Thanks in advance

1 Answer 1

1

c_str() returns a polymorphic object convertible to either const char* or const wchar_t*, so in case of ambiguity you need to select what exactly do you need. However in this case, you can avoid this ambiguity completely by doing

std::string azonosito(ItemID->GetLabelText().c_str()); 

or, even more clearly,

std::string azonosito(ItemID->GetLabelText().ToStdString()); 
Sign up to request clarification or add additional context in comments.

Comments