用户验证的C++小程序 mysql++

前提:安装mysql 和mysql++、mysql++-devel

程序:#include<iostream>
#include "mysql++.h"
#include <string>
using namespace mysqlpp;
using namespace std;
int main()
{       char  usrstr[30];
        bool  userexist=false;
        cout<<"Please input your username:";
        cin>>usrstr;

//建立连接
        mysqlpp::Connection con(false);
        if(con.connect("test","localhost","root",""))

// test is db name ,localhost is server host name 
        {
                cout<<"success"<<endl;
                mysqlpp::Query query=con.query("select username from userlist");
                mysqlpp::StoreQueryResult res=query.store();
                for (int i=0;i<res.num_rows();i++)
                {
                if (strcmp(usrstr,res[i][0])==0)
                        userexist=true;
                }
                if (userexist)
                        cout<<"Welcome "<<usrstr<<endl;
   }

}

 编译连接:g++ -L /usr/lib/mysql -lmysqlclient -L /usr/lib -lmysqlpp -Ilib -I/usr/include/mysql -I/usr/include/mysql++ userlogin.cc -o userlogin.o

ps:

-Idir
  在你是用#i nclude"file"的时候,gcc/g++会先在当前目录查找你所制定的头文件,如果没有找到,他回到缺省的头文件目录找,如果使用-I制定了目录,他会先在你所制定的目录查找,然后再按常规的顺序去找.
  对于#i nclude<file>,gcc/g++会到-I制定的目录查找,查找不到,然后将到系统的缺省的头文件目录查找

-Ldir
  制定编译的时候,搜索库的路径。比如你自己的库,可以用它制定目录,不然编译器将只在标准库的目录找。这个dir就是目录的名称。

传递给会连接程序.

  -llibrary

原文地址:https://www.cnblogs.com/jewell/p/2092629.html