【发布时间】:2015-03-20 00:55:52
【问题描述】:
我尝试在 vs 2013 中将数据绑定到文本块。
但是当我尝试将列表项转换为字符串时遇到了一些问题。
这是来自 vs 的错误信息:
no instance of constructor "std::basic_string<_Elem, _Traits,
_Alloc>::basic_string [with _Elem=wchar_t,
_Traits=std::char_traits<wchar_t>, _Alloc=std::allocator<wchar_t>]"
matches the argument list argument types are:
(std::_List_iterator<std::_List_val<std::_List_simple_types<std::string>>>)
这是我的代码:
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);
std::wstring s1(*en);
std::string s2(*en);
ENTEXT->Text = s2; //ENTEXT is textblock name
我正在尝试将列表元素传递给文本块,但是这段代码显示了
错误 C2664 : 'void Windows::UI::Xaml::Controls::TextBlock::Text::set(Platform::String ^)' : 无法将参数 1 从 'std::string' 转换为 'Platform ::字符串 ^'
【问题讨论】:
-
请提供工作代码示例或至少提供更多信息。例如
cn是什么? -
错误看起来很清楚。您不能从单个列表迭代器创建字符串。推进
c1.begin()不应该编译。 -
std::wstring 没用,避免使用
-
我认为您实际上想要一个向量。
-
嗨,我已经更新了我的代码..谢谢
标签: c++