2010-01-22 81 views
0

只需要设置lbl.caption(在一个循环内),但问题比我想象的要大。我甚至尝试过使用wstrings的矢量,但是没有这种东西。我读过一些网页,尝试像WideString的()的UnicodeString()的一些功能,我知道我不能,不应该在C++ Builder的2010年C++ builder,label.caption,std :: string to unicode conversion

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; 

宁可关掉的Unicode:[BCC32错误] myFile.cpp(129):E2034无法将'std :: string'转换为'UnicodeString'

它现在吃了几个小时。有没有“快速&脏”的解决方案?它只是工作...

UPDATE

解决。我混合了STL/VCL字符串类。谢谢TommyA

回答

5

问题是你在混合standard template library string classVCL string class。标题属性需要VCL字符串,它具有STL的所有功能。

工作的例子确实通过了(const char*),这很好,因为在VCL UnicodeString类构造函数中有这样的构造函数,但是没有用于从STL字符串复制的构造函数。

你可以做两件事情之一,你可以用你的载体,而不是STL的人的VCL串类之一,因此:

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

变为:

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

在这两种情况下底线也会起作用。另外,您可以检索来自STL字符串的实际空终止字符指针,并将其传递给字幕,此时它会被转换成VCL String类是这样的:

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

你更喜欢哪一个解决方案是高达你,但除非你对STL字符串类有特殊需求,否则我会强烈建议你使用VCL字符串类(正如我在第一个例子中所展示的那样)。这样你就不必拥有两个不同的字符串类。

+0

太棒了..非常感谢你..这几年我没有使用VCL。 – qlf00n 2010-01-22 18:32:05