我保持在视觉工作室接受C2664转换错误错误C2664从常量的std :: string转换为的std :: string&
它告诉我,它不能从常量性病转换参数1 ::字符串std :: string &。我尝试在stringToWstring原型和函数本身中添加/删除const,并且错误仍然出现。
wstring hexval = buff.substr(buff.find(L"hex(2):"));
wstring h;
wchar_t ch;
typedef boost::tokenizer<boost::char_separator<wchar_t> > tokenizer;
boost::char_separator<wchar_t> sep(L"//,");
tokenizer tokens(hexval, sep);
for(tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); tok_iter++)
{
ch = someFunction(*tok_iter); //error here
h += ch;
}
wstring stringToWstring(const string& s)
{
wstring temp(s.length(), L'');
copy(s.begin(), s.end(), temp.begin());
return temp;
}
wchar_t someFunction(const wstring &hex_val)
{
}
任何想法?
编辑:
我看,这是真的令人困惑所以我要解释一点..
本来,我想要的是里面的这些线环
ch = someFunction(*tok_iter);
h += ch
我也期待* tok_iter返回一个wstring,但我得到一个错误,如:无法将参数1从const std :: string转换为const std :: wstring &
因此,我认为,* tok_iter是一个const std :: string,因此我创建了一个stringToWstring函数来完成转换。要为循环
ch = someFunction(stringToWstring(*tok_iter));
h += ch
当我这样做,这样做的,我得到:
Error 1 error C2664: 'std::_String_const_iterator<_Elem,_Traits,_Alloc>::_String_const_iterator(const std::_String_const_iterator<_Elem,_Traits,_Alloc> &)' : cannot convert parameter 1 from 'std::_String_const_iterator<_Elem,_Traits,_Alloc>' to 'const std::_String_const_iterator<_Elem,_Traits,_Alloc> &' c:\program files\boost\boost_1_39\boost\tokenizer.hpp 63
我希望这是更清晰了。
什么“粗体部分”? – 2009-08-20 18:06:20
为什么你问关于将字符串转换为wstring,如果错误谈到const字符串字符串&? – jalf 2009-08-20 18:07:01
周围有双星号的部分,如果不在代码块中,则会加粗。 – chaos 2009-08-20 18:07:21