Reputation: 3922
I want to remove blank space from a const string, but when i used remove function its showing error that const string cant modify.
const QString abc = "hello world";
QString def = " ";
QString mk = abc .remove(def); // Here error saying const cant change
Please Help
Upvotes: 0
Views: 1025
Reputation:
The same operation without additional variable:
const QString abc = "hello world";
QString def = " ";
QString mk = abc;
mk.remove(def);
Upvotes: 0
Reputation: 6329
You can't modify a const String. QString::remove returns a reference to abc, so remove works on abc, mk is not a copy but abc again!! Look for functions which are const functions if you want to operate on a const object.
EDIT:
const QString abc = "hello world";
QString ijk = abc;
QString def = " ";
QString mk = ijk .remove(def); // Here error saying const cant change
Upvotes: 2