I was making a small text editor in c++ for fun and the code worked, though a bit slow, but when I tried to paste something into the editor, I ran into a problem. When I typed ctrl+v, instead of it pasting the copied text, which was a web link, it showed this: ▬. This happened when I actually pressed ctrl+c or ctrl+s or any letter with ctrl at the beginning to be fair. Why does this happen and is there a way to stop this?
int editTxtFile() {
std::string txtstr;
std::string filename;
std::cin >> filename;
std::ofstream file("TXTFILES\\"+filename+".txt", std::ios::out);
std::cout << "This is an editor for txt files (sorry for the flashing!)\n";
char keypressed;
int asciiVal;
if (file.is_open()) {
while (true) {
keypressed = getch();
asciiVal = keypressed;
switch (asciiVal) {
case 13:
txtstr += "\n";
system("cls");
break;
case 8:
txtstr = txtstr.substr(0, txtstr.size() - 1);
system("cls");
break;
case 94:
file << txtstr;
system("cls");
file.close();
break;
default:
txtstr += keypressed;
system("cls");
break;
}
std::cout << txtstr;
}
}
return 0;
}
I am using the header file conio.h for the getch() function. How can I fix this problem? Thank you in advance.