简体   繁体   中英

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

I am using visual studio 2013 to developing windows 8 app. I trying to binding list element data to textblock,But i cannot pass list element to text block by the code.

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. Try with *en and it should work

Edit: sorry, i didn't realise theat your textblock was a managed code (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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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