Try to use my optimize version.
It is likely C version, but anyway more optimize about space and memory.
Regards.
Now I've fixed event when input data buffer longer than expected.
Thanks.
Regards.
Code:
#include <iostream>
using namespace std;
char def_pass[]="iloveyou";
int main()
{
static int i = strlen(def_pass)+1;
char* pPassword = new char[i];
cout << "Please enter the password:\n";
//cin >> pPassword; // ok, maybe error
fgets (&pPassword[0], i, stdin) ; // replacement
if (strcmp(pPassword,def_pass)!=0)
{
cerr << "Incorrect password.";
return 1;// exit program with error code = 1
}
cout << "Correct password.";
delete pPassword;
//
//program begin here!
//
return 0;
}