string str;
cout << "Enter code\n";
getline(cin, str, '~');
//some loop i can't figure out
size_t nFPos = str.find('//');
size_t second = str.find('\n', nFPos);
size_t first = str.rfind('\n', nFPos);
str.erase(first, second - first);
//end unknown loop
INPUT
code
//comment
//COMMENT
code~
OUTPUT
code
//COMMENT
code
I cannot for the life of me figure out what kind of loop I should use for it to delete ALL comments starting with //. It's only deleting the first comment and bypassing everything else.
I've tried for, while, do while, and if
I can't figure it out