问题
include
<iostream>
#include
<vector>
using namespace std
;
int main(){
string str
="hello world";
vector
<char> res
;
for(unsigned i
= str
.size()-1; i
>= 0; i
--){
res
.push_back(str
[i
]);
}
for(unsigned i
=0;i
<res
.size();i
++){
cout
<<res
[i
];
}
return 0;
}
输出结果:
解决办法: 将第一个for循环的unsigned换成int
for(int i = str.size()-1; i >= 0; i--){
res.push_back(str[i]);
}
原因:暂时没有找到原因,猜测是string对[]运算符重载时的写法导致。