简体   繁体   English

如何在C ++ Visual Studio 2013中将列表元素转换为文本块

[英]How to convert list element to textblock in C++ visual studio 2013

I am using visual studio 2013 to developing windows 8 app. 我正在使用Visual Studio 2013开发Windows 8应用程序。 I trying to binding list element data to textblock,But i cannot pass list element to text block by the code. 我试图将列表元素数据绑定到textblock,但是我无法通过代码将list元素传递到textblock。

list <string> c1;

 //Insert Data
 c1.push_back("one");
 c1.push_back("two");
 c1.push_back("three");
 c1.push_back("Four");
 c1.push_back("Five");
 c1.push_back("Six");
 c1.push_back("Seven");
 c1.push_back("Eight");
 c1.push_back("Nine");
 c1.push_back("Ten");




 //Random data from list

 int RandNum = 0 + (std::rand() % 10);

 auto en = c1.begin();
 advance(c1.begin(), RandNum);





 ENTEXT->Text = en; //ENTEXT is textblock name 

Because en is an iterator. 因为en是迭代器。 Try with *en and it should work 尝试使用*en ,它应该可以工作

Edit: sorry, i didn't realise theat your textblock was a managed code (aka cli) String^ : 编辑:抱歉,我没有意识到您的文本块是托管代码(aka cli) String^

 ENTEXT->Text  = gcnew String(en->c_str());  // convert std::string into String^

This conversion from standard strings to microsoft's framework strings is well explained in this article: How to convert Standard String to System::String 从标准字符串到Microsoft框架字符串的这种转换在本文中得到了很好的解释: 如何将标准字符串转换为System :: String

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM