这个c++程序有么问题?

来源:百度知道 编辑:UC知道 时间:2024/09/25 08:32:37
#include <iostream>
#include <string>//注意这里的头文件!
using namespace std;

void main( void )
{
cout<<"请输入密码: "<<endl;
string password;
int i=0;
char ch;
while ((ch=_getch())!=13)
{
password+=ch;//string对象重载了+=
cout<<"*";
}
cout<<endl<<"输入完毕!您输入的是: "<<password<<endl;
}

帮我看看这个程序,哪里错了。我调半天没弄出来

你没include _getch的那个头文件呗。 好像是conio.h ?

是getch(),不是_getch(),而且用这个函数要包含conio.h头文件。
#include <iostream>
#include <conio.h>
#include <string>//注意这里的头文件!
#include <conio.h>
using namespace std;

void main( void )
{
cout<<"请输入密码: "<<endl;
string password;
int i=0;
char ch;
while ((ch=getch())!=13)
{
password+=ch;//string对象重载了+=
cout<<"*";
}
cout<<endl<<"输入完毕!您输入的是: "<<password<<endl;
}