当按下enter键时我试图打破循环,因此用户输入密码,然后在完成后按Enter键。但它似乎没有起作用。
#include "stdafx.h"
#include<iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include<conio.h>
#include <cstring>
using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::strlen;
#define SIZE 10
int main()
{
char num[SIZE];
cout << "Enter a password " << endl;
for (int i = 0; i < SIZE; i++) {
num[i] = _getch();
cout << num[i];
if (num[i] == '\n') {
cout << "heey" << endl;
break;
}
}
cout << endl;
cout << " it is : ";
for (int i = 0; i < SIZE; i++) {
cout << num[i];
}
cout << endl;
return 0;
}