STRING支不支持字符反转啊?
words_temp.insert(words_temp.begin(), words.rbegin(), words.rend());
编译无法通过,而
words_temp.insert(words_temp.begin(), words.begin(), words.end());
可以
string应该支持rbegin()的啊?
问题点数:20、回复次数:5Top
1 楼windking21(想玩玩WOW 真的那么难吗)回复于 2005-08-03 16:43:51 得分 4
#include <algorithm>
reverse(vec.begin(),vec.end());Top
2 楼silence_jiliao(寂寥客)回复于 2005-08-03 16:51:23 得分 4
终于搞定了!!谢谢啊
那为什么上面不支持 rbegin()呢??Top
3 楼zhouhuahai(道号"虚无")回复于 2005-08-03 19:35:39 得分 4
因为insert里的iterator是++的
你可以去看看STL源码Top
4 楼qhfu(改个名字)回复于 2005-08-03 20:36:15 得分 4
#include<string>
using namespace std;
string s = "abc";
string s2;
s2.insert(s2.begin(),s.rbegin(),s.rend());
这个可以的阿
Top
5 楼silence_jiliao(寂寥客)回复于 2005-08-03 22:34:40 得分 4
晕,我也试成功了,在DEV-C++下面测试成功的;
在VC6下面无法通过,提示
Compiling...
Cpp1.cpp
C:\Documents and Settings\Solidus\Desktop\C++ temporary\string_class\Cpp1.cpp(9) : error C2664: 'class std::basic_string,class std::allocator > &__thiscall std::basic_string,class std::allocator >::insert(unsigned int,const char *,unsigned int)' : cannot convert parameter 1 from 'char *' to 'unsigned int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.
看来VC是不能用了……Top




