c++ - 将字符串放入控制台,具有编辑能力

标签 c++ string windows

<分区>

C++ 中的什么函数可以将字符串放入控制台,并具有编辑功能?我有这样的控制台状态:enter image description here

完成所需功能后,我想看到这个:

enter image description here

但不是这个:

enter image description here

最佳答案

它不能在终端上本地完成,你必须在你的控制流中完成。

一个小例子

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/

相关文章:

windows - 为什么 Strawberry Perl 不调用我的 DllMain?

windows - python easysnmp packge install error windows..失败,退出状态为2

windows - 为什么 TClientSocket.OnRead 事件会为单个服务器发送两次

c++ - 如何将 Json 文件中的数据转换为值 (double,int...)

c++ - 在 C++ 中将 Ascii 字符存储在数组中

python - Pandas 系列的矢量化格式函数

c - 使用 sscanf 读取字符串的剩余部分

java - 从字符串中删除随机字符

c++ - Boost ptree 读取 xml 中的结束标记 xml 验证不正确

c++ - 多种输出格式的设计模式