对于string 这个类型我不是很会,你问问高手吧
回复 10楼 yxieguodong
好像可以直接比较,运行通过了。两个char[]比较还出错了。。
程序代码:#include <conio.h>
#include <cctype>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
char c;
int i=0;
string pas;
while ((c=getch())!='\r')
{
if (c=='\b') {
putch(c);
putch(' ');
putch(c);
if (!pas.empty()) pas=pas.erase(pas.size()-1,1);
}
else if (isprint(c)){
putch('*');
pas+=c;
}
}
cout<<endl;
cout<<pas<<endl;
return 0;
}
可以退格的星号输出~
程序代码:#include<iostream>
#include<string>
#include<conio.h>
using namespace std;
void mima(string& key)
{
char c;
for(int i=0;i<15;i++)
{
c = getch();
if (c == 13)
{
c='\0';
break;
}
else
{
cout << '*';
}
key = key + c;
}
}
int main()
{
string a;
mima(a);
cout << endl << a << endl;
return 0;
}