I'm editing a python file and my program iterates through every line and if the string "if" exists, it appends a comment to it. The program does work but it adds ^M and I can no longer see the code on GitHub as it appears as a raw file.
Looking at this post here https://unix.stackexchange.com/questions/32001/what-is-m-and-how-do-i-get-rid-of-it
I used the commend dos2linux and then ran my program, and the ^M characters did not appear but I still cannot see the code on GitHub.
Here is the code in question
int main(){
ifstream myfile ("file.py", ios::binary);
ofstream newfile ("newfile.py", ios::binary);
string line;
string newline;
string yep = "if";
size_t check;
while ( getline(myfile,line)){
check = line.find("if");
if ( check != string::npos){
newline = line + "#If statement";
newfile << newline << '\n';
} else {
newline = line;
newfile << newline << '\n';
}
}
myfile.close();
newfile.close();
return 0;
}