注册 登录
编程论坛 C++教室

求教在用getch()接收字符时如何删除输入错误的字符啊,它为什么将backspace键当字符接收了啊???

smile康师傅 发布于 2012-11-11 00:15, 2440 次点击
代码如下:
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
    char ch;
    while(1)
    {
        ch=getch();
        if(ch!=13)
        {
            cout<<'*';
        }
        else
            break;
    }
    cout<<endl;
}
为社么在输入的过程中删除不了输错的字符啊???求各位大神看看,指点下哈!!!!!
2 回复
#2
azzbcc2012-11-11 00:31
程序代码:
#include <iostream>
#include <conio.h>
using namespace std;
void RePrint(int a)
{
    int i;
    system("cls");
    for (i = 1;i <= a;i++)
        cout<<'*';
}
void main()
{
    char ch;    int i = 0;
    while (1)
    {
        ch = getch();
        if (ch == 13)
            break;
        if (ch == 8)
        {
            i--;
            RePrint(i);
            continue;
        }
        cout<<'*';
        i++;
    }
    cout<<endl;
}
#3
smile康师傅2012-11-11 14:23
好,了解了。。。谢了哈
1