自己写的密码登陆程序,不清楚怎么和数据库连接,暂时把输入的存在了文件中!还望高手指点!
[code=C/C++][/code]
#include <iostream>
#include <map>
#include <string>
#include <fstream>
#include <conio.h>
using namespace std;
//密码输入函数:
void code_input(char &m_ch, string &m_code1)
{
cout << "请输入你的密码:\n";
while(m_ch = getch())
{
if(m_ch != 13)
{
m_code1 += m_ch;
putchar('*') ;
}
else
break;
}
}
//检索密码和帐号
void save_look( map<string,string> &m_mp, string &m_account, string &m_code)
{
string str1,str2;
ifstream input("113.txt");
while(input >> str1 >> str2)
m_mp.insert(make_pair(str1,str2));
input.close();
map<string,string>::iterator iter = m_mp.find(m_account);
if(iter == m_mp.end())
{
cout << "\n这个帐号不存在,是否要创建?请输入Y或者N" << endl;
char ch1;
while (cin >> ch1)
{
if(ch1 == 'Y')
{
m_mp.insert(make_pair(m_account,m_code));
ofstream output("113.txt", ios::app | ios::out);
//output.open("113.txt");
//output.seekp(0,ios::end);
output << m_account << '\n' << m_code << endl;
output.close();
cout << "创建成功!" << endl;
exit(0);
}
else if(ch1 =='N')
{
exit(0);
}
else
{
cout << "输入错误! 请重新输入!" <<endl;
}
}
}
else
{
int i = 1;
while(m_mp[m_account] != m_code)
{
char ch1;
cout << "\n密码错误请重新输入!" << endl;
m_code = "";
i++;
if(i == 5)
{
cout << "\n对不起你重复次数太多!" << endl;
exit(0);
}
else
{
code_input(ch1,m_code);
}
}
cout << "\n帐号密码正确!" << endl;
}
}
void main()
{
map<string,string> mpv;
string account,code;
char ch;
cout << "请输入你的帐号:\n";
cin >> account;
code_input(ch,code);
save_look(mpv,account,code);
}
[解决办法]
指点什么?如何连数据库?你数据库是什么型的?你的程序又是在什么平台上运行的?