c++的string中有逆序存储的函数吗?

2025-12-17 10:29:20
推荐回答(4个)
回答1:

印象中CString没有这么个函数,不过你一样可以用strrev();来对C++的string进行逆序,因为C++的字符串跟c的是一样的。如果你用mfc的CString,那你可以这样

CString a = "abcdefg";
strrev(a.GetBuffer());//这样a就逆序了。

GetBuffer就是得到char*,把CString跟char*一样处理了

回答2:

#include
#include
using namespace std;
int main()
{
string str("cvicses");
string s(str.rbegin(),str.rend());
cout << s < return 0;
}
//呵呵!既然是c++的string,可以考虑用用string的反向迭代器了

回答3:

没有哦
但是可以这样用
#include
#include
#include
using namespace std;
void main()
{
string s="abcde";
strrev((char *)s.c_str());
cout<}

调试通过,仍然是用c里面的strrev()函数,呵呵

回答4:

在C++中string属于容器.你可以定义一个string迭代器,用sort算法实现排序,你去试试。