Search code examples
c++qtqstring

Is there a way to increment QString?


Is there a way to increment a QString in C++- something like:
QString str("a");
str++;
qDebug()<<a; //Here i want letter "b"

EDIT: Yes, basically i want to increment a one letter but incrementing longer string would be good.


Solution

  • You can't really increment a string because you would first have to define how that would work. For example, where would the values wrap arround.

    You can increment the characters though, but even this will only work for meaningful character sequences:

    str[0].unicode()++;

    EDIT: reaction OP comments

    If you just want to switch between scenarios, this is the code you wan to use:

    enum Scenarios { ScenarioOne, ScenarioTwo, ScenarioThree, ScenariosCount };
    
    Scenarios var = ScenarioOne;
    var++;