Take the 2-minute tour ×

Just need to set the lbl.caption (inside a loop) but the problem is bigger than i thought. I've tried even with vector of wstrings but there is no such thing. I've read some pages, tried some functions like WideString(), UnicodeString(), i know i can't and shouldn't turn off Unicode in C++Builder 2010.

std::vector <std::string> myStringVec(20, "");
myStringVec.at(0) = "SomeText";
std::string s = "something";

// this works ..
Form2->lblTxtPytanie1->Caption = "someSimpleText";

// both lines gives the same err
Form2->lblTxtPytanie1->Caption = myStringVec.at(0);
Form2->lblTxtPytanie1->Caption = s;

Err: [BCC32 Error] myFile.cpp(129): E2034 Cannot convert 'std::string' to 'UnicodeString'

It ate me few hours now. Is there any "quick & dirty" solution ? It just has to work...


Solved. I've mixed STL / VCL string classes. Thank You TommyA.

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

The problem is that you are mixing standard template library string class with the VCL string class. The caption property expects the VCL string which has all the functionality of the STL one.

The example that works is really passing (const char*) which is fine because there is a constructor for this in the VCL UnicodeString class constructor, however there isn't a constructor for copying from STL strings.

You could do one of two things, you could use one of the VCL string classes in your vector instead of the STL ones, so that:

myStringVec.at(0) = "SomeText";
std::string s = "something";


std::vector <String> myStringVec(20, "");
myStringVec.at(0) = "SomeText";
String s = "something";

In which case the bottom two lines will also work. Alternatively you can retrieve the actual null terminated character pointer from the STL strings and pass them to the caption, at which point it will be converted into a VCL String class like this:

// both lines will now work
Form2->lblTxtPytanie1->Caption = myStringVec.at(0).c_str();
Form2->lblTxtPytanie1->Caption = s.c_str();

Which solution you prefer is up to you, but unless you have some specific need for the STL string class I would strongly suggest you going with the VCL string classes (as I showed in my first example). This way you won't have to have two different string classes.

share|improve this answer
Great.. Thank You Very Very much .. It's been few years i didn't use VCLs. –  qlf00n Jan 22 '10 at 18:32
add comment

Your Answer


