<分区>
C++ 中的什么函数可以将字符串放入控制台,并具有编辑功能?我有这样的控制台状态:
完成所需功能后,我想看到这个:
但不是这个:
最佳答案
它不能在终端上本地完成,你必须在你的控制流中完成。
一个小例子
string text("Hello, World")
cout << text;
char x = getch();
while (x != '\n') { //loop breaks if you press enter
if (x == 127 || x == 8) { //for backspace(127) and delete(8) keys
cout << "\b \b"; //removes last character on the console
text.erase(text.size() - 1);
}
else {
cout << x;
text.append(x);
}
x = getch();
}
"\b"
是非破坏性退格键。即它向后移动光标但不删除。
"\b\b"
是破坏性的退格键。
关于c++ - 将字符串放入控制台,具有编辑能力,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37097155/