使用C ++旋转字符串 [英] Rotating a string using C++

查看:119
本文介绍了使用C ++旋转字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

使用c ++旋转字符串?

如何旋转std :: string?

c ++,与命令行输入一起使用。我在命令行中输入一个字符串

I am making a application in c++ that works with Command line input. I am entering a string in to the command line

    int main(int argc, char** argv)
    {
        if(argc != 2)
        {
             cerr << "Invalid number of CMD arguments" << endl;
             return 1;
        }

        string StringValue = argv[1];
        cout << StringValue << endl;
     }

这项工作很好。现在我想循环字符串中的字符。
例如:如果我输入单词STATES。

This work's fine. Now i want to loop the character in the string. Example: if i enter the word "STATES".

    ^STATES|
    |^STATES
    S|^STATE
    ES|^STAT
    TES|^STA
    ATES|^ST
    TETES|^S
    STATES|^

其中^是开头,结束。

Where "^" was the start and "|" the end. how do i do this?

推荐答案

使用 std :: rotate a href =http://www.cplusplus.com/reference/algorithm/rotate/> http://www.cplusplus.com/reference/algorithm/rotate/

use std::rotate http://www.cplusplus.com/reference/algorithm/rotate/

string foo = "abcdefg";
std::rotate(foo.begin(), foo.begin() + 3, foo.end());
cout << foo << endl; //prints defgabc

这篇关于使用C ++旋转字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆