I am having a problem with removing all instances of "amp;" in a string in c++, I have created a loop to replace "amp;" with "" until there are no "amp;" instances left. I am having an unknown error where the program starts printing random characters, I have never seen it before. There is an image below. I have used mutliple other loops to remove things in the same program, so I am unsure why it is happening now.
Character Glitch: https://screenrec.com/share/EcVLHoasvU
This is the loop I have used:
try {
while(DownloadLink.find("amp;") != string::npos){
DownloadLink.replace(DownloadLink.find("amp;"), 4, "");
}
} catch (const exception& Error) {
cerr << "Error: " << Error.what();
}
For a minimal reproducible example:
#include <iostream>
#include <string>
using namespace std;
int main() {
string DownloadLink;
DownloadLink = "https://rr2---sn-gjo-w43l.googlevideo.com/videoplayback?expire=1685464604&ei=vNF1ZPypCYLk8wS04YS4Bw&ip=193.135.13.240&id=o-AOroxIeyjf0SXpp4Jjav3mMxHNrQnAmWFHliIzDxKFK8&itag=22&source=youtube&requiressl=yes&mh=xJ&mm=31%2C29&mn=sn-gjo-w43l%2Csn-ab5sznly&ms=au%2Crdu&mv=m&mvi=2&pl=24&initcwndbps=248750&spc=qEK7B7YCjgMFmSN1lRYNJdgmcwOfjSE&vprv=1&svpuc=1&mime=video%2Fmp4&ratebypass=yes&dur=1535.256&lmt=1685416420579114&mt=1685442532&fvip=1&fexp=24007246%2C24362688%2C51000022&beids=24350017&c=ANDROID&txp=4318224&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cspc%2Cvprv%2Csvpuc%2Cmime%2Cratebypass%2Cdur%2Clmt&sig=AOq0QJ8wRAIgOFevBFo84_aL0L8hSD1vwztRDGStTF6OaohO4gA8OIUCIE1wN5685dZ7FROQXO9W7BOv4thF8B3KxFE6iefy60xS&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhAOO9mtQzsKDrCes2EPmTwOyB8QtGblPFo30I9VrOsSnMAiEAh91ImIfeaugrIfJ4Q0U30viktdo4sWHv0ywQV0kfjt8%3D&title=Ages+1+-+100+Fight+For+$500,000";
while(DownloadLink.find("amp;") != string::npos){
DownloadLink.replace(DownloadLink.find("amp;"), 4, "");
}
cout << DownloadLink;
return 0;
}
Has anyone seen anything like this before or knows how to help? Thanks