我想复制a的内容vector
到一长string
带有自定义分隔符。到目前为止,我已经尝试过:
// .h
string getLabeledPointsString(const string delimiter=",");
// .cpp
string Gesture::getLabeledPointsString(const string delimiter) {
vector<int> x = getLabeledPoints();
stringstream s;
copy(x.begin(),x.end(), ostream_iterator<int>(s,delimiter));
return s.str();
}
但我得到
no matching function for call to ‘std::ostream_iterator<int, char, std::char_traits<char> >::ostream_iterator(std::stringstream&, const std::string&)’
我尝试过charT*
但我得到
error iso c++ forbids declaration of charT with no type
然后我尝试使用char
and ostream_iterator<int>(s,&delimiter)
但我在字符串中收到奇怪的字符。
谁能帮助我理解编译器在这里期望什么?
Use delimiter.c_str()作为分隔符 http://ideone.com/dnVp6:
copy(x.begin(),x.end(), ostream_iterator<int>(s,delimiter.c_str()));
这样,你就得到了一个const char*
指向字符串,这就是ostream_operator
期望从你的std::string
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)