hello lets say we have string x = "abcdefgh";
what i want to do is to remove letters for example i would like to make from this is just bcdefgh and then cdefgh i dont want to use substring and i wanted to do smth like x[0] = ""; so i can clear that space in string but it doesnot work , any ideas guys ? thanks.
string x = "Tarik Neaj";
x.replace(0,2, ""); // First parameter tells it where to begin. Second how many characters to replace, third what to replace it with.
cout << x << endl;
Problem is that. Its replacing them completely, thats what this function does.
you have your string to begin with
string z = "12345".
Your loop runs 4 times. First loop you replace 1 with nothing. So it outputs
2345
.
Now your string looks like this - "2345".
So the second round of the loop, you replace the first position string, which is now 2, and then 2 characters. So it removed 2 and 3, now your output is
45
.
If you want the output you requested, you have to re-give your string the original value.
1 2 3 4 5 6 7 8
string z = "12345";
for (int i = 1; i < z.length(); i++)
{
z.replace(0, i, "");
cout << z << endl;
z = "12345"; // here
}