Reputation: 261
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.
Upvotes: 1
Views: 1088
Reputation: 4954
You can't increment or decrement a QString because the ++ and -- operators are not defined for that class, and there is no clear concept of what incrementing a string might mean (while it might be clear to you, it is not clear enough to make it part of the standard Qt library).
What you could do is create a subclass of QString, then implement operator++() and operator--(). With such a subclass, you would retain all the features of a standard QString, while having it behave exactly as you want for incrementing and decrementing.
Upvotes: 1
Reputation: 36433
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++;
Upvotes: 4