例外:h:VisualC++和MySQL连接 我试图用Visual C++连接MySQL数据库。 我会从MySQL的网站下载必要的文件。然后我按照网站提供的说明创建了我的项目

例外:h:VisualC++和MySQL连接 我试图用Visual C++连接MySQL数据库。 我会从MySQL的网站下载必要的文件。然后我按照网站提供的说明创建了我的项目,c++,mysql,visual-studio-2012,C++,Mysql,Visual Studio 2012,现在,当我点击Build时,它给了我错误 Error 1 error C2059: syntax error : 'string' c:\program files\mysql\mysql connector c++ 1.1.7\include\cppconn\exception.h 98 1 MySQL_Connection Error 2 error C2091: function returns function c:\program files\mys

现在,当我点击Build时,它给了我错误

Error   1   error C2059: syntax error : 'string'    c:\program files\mysql\mysql connector c++ 1.1.7\include\cppconn\exception.h    98  1   MySQL_Connection
Error   2   error C2091: function returns function  c:\program files\mysql\mysql connector c++ 1.1.7\include\cppconn\exception.h    98  1   MySQL_Connection
Error   3   error C2802: static member 'operator new' has no formal parameters  c:\program files\mysql\mysql connector c++ 1.1.7\include\cppconn\exception.h    98  1   MySQL_Connection
Error   4   error C2333: 'sql::SQLException::operator new' : error in function declaration; skipping function body  c:\program files\mysql\mysql connector c++ 1.1.7\include\cppconn\exception.h    98  1   MySQL_Connection
Error   5   error C2556: 'void *(__cdecl *sql::SQLException::operator new(void))(size_t,void *) throw()' : overloaded function differs only by return type from 'void *(__cdecl *sql::SQLException::operator new(void))(size_t) throw(std::bad_alloc)'  c:\program files\mysql\mysql connector c++ 1.1.7\include\cppconn\exception.h    98  1   MySQL_Connection
Error   6   error C2556: 'void *(__cdecl *sql::SQLException::operator new(void))(size_t,const std::nothrow_t &) throw()' : overloaded function differs only by return type from 'void *(__cdecl *sql::SQLException::operator new(void))(size_t) throw(std::bad_alloc)'  c:\program files\mysql\mysql connector c++ 1.1.7\include\cppconn\exception.h    98  1   MySQL_Connection
Error   7   error C2090: function returns array c:\program files\mysql\mysql connector c++ 1.1.7\include\cppconn\exception.h    98  1   MySQL_Connection
Error   8   error C2556: 'void *(__cdecl *sql::SQLException::operator new(void))(size_t,std::allocator<_Ty> &)' : overloaded function differs only by return type from 'void *(__cdecl *sql::SQLException::operator new(void))(size_t) throw(std::bad_alloc)'   c:\program files\mysql\mysql connector c++ 1.1.7\include\cppconn\exception.h    98  1   MySQL_Connection
Error   9   error C1083: Cannot open include file: 'boost/scoped_ptr.hpp': No such file or directory    C:\Program Files\MySQL\MySQL Connector C++ 1.1.7\include\mysql_driver.h 30  1   MySQL_Connection
也许这违反了超载规则。 我应该如何解决这个问题?我只想用C++编写代码,而不是用C.</P>编写代码 整个文件:

// MySQL_Connection.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include <stdio.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#define DB_HOST_NAME "localhost"
#define DB_USERNAME "root"
#define DB_PASSWORD "Passw0rd"
#define DB_SCHEMA_NAME "TESTDB"

//#include "mysql_connection.h"

#include <cppconn/driver.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>

// The one and only application object

using namespace std;
using namespace sql;



int main(int argc, char * argv[])
{

    Driver *driver;
    Connection *con;
    ResultSet *rs;
    Statement *stmt;
    PreparedStatement  *pre_stmt;

    int id;
    char* name;
    char flag;
    cout << "Connecting to MySQL database...";

    /* Create a connection */
    driver = get_driver_instance();
    con = driver->connect(DB_HOST_NAME, DB_USERNAME, DB_PASSWORD);

    try
    {
        if ( con->isValid() ) /* This method is used to check that mysql connection is alive or not */
        {
        /* Connect to mysql database */
            con->setSchema(DB_SCHEMA_NAME);


            /* Creating statement for inserting data into test table */
            stmt = con->createStatement();
            stmt->execute("USE " DB_SCHEMA_NAME );
            stmt->execute("DROP TABLE IF EXISTS test");
            stmt->execute("CREATE TABLE test ( id INT, name VARCHAR(30) )");

            cout << "\nTable is created.";
            cout << "\n\n Below Operations are done by \"Statement.\"";

            stmt->execute("INSERT INTO test VALUES ( 1, 'Unnat' ) ");
            stmt->execute("INSERT INTO test VALUES ( 2, 'Kunal' ) ");
            stmt->execute("INSERT INTO test VALUES ( 3, 'Abhishek' ) ");
            stmt->execute("INSERT INTO test VALUES ( 4, 'Mithun' ) ");
            stmt->execute("INSERT INTO test VALUES ( 5, 'Kiran' ) ");

            cout << "\nData Inserted.";

            delete stmt;

            /* Creating statement for fetching data from test table*/
            stmt = con->createStatement();
            rs = stmt->executeQuery("SELECT * FROM test ORDER BY id ASC");

            cout << "ID\tNAME\n";
            cout << "--\t----\n";

            while ( rs->next() ) // next() will check weather next data is present or not
            {
                /*
                    * rs->getInt(x) : get the numbered column data, specified in parameter
                        [ NOTE ] : column number starts form 1, not 0.
                    * rs->getString ( "column-name" ) :  fetch data of given column in parameter
                */
                cout << rs->getInt(1) << rs->getString("name");
            }

            delete rs;
            delete stmt;

            /* Insert operation using PreparedStatement. */
            cout << "\nInsert operation using PreparedStatement.\n\n";

            do 
            {
                pre_stmt = con->prepareStatement("INSERT INTO test VALUES ( ?, ? ) ");

                cout << "ID : ";
                cin >> id;

                cout << "Name : ";
                cin >> name;

                pre_stmt->setInt ( 1, id );
                pre_stmt->setString( 2, name );

                cout << "Data Added.\n";

                cout << "\nDo you want to continue? [Y/N] :";
                cin >> flag;
            } while (flag == 'Y' || flag == 'y');

            delete pre_stmt;
        }
    }
    catch (exception e)
    {
        cout << "Error :";
        //cout << "Error on " << __LINE__ << " \n\t in ( " << __FUNCTION__ << " ) ";
        e.what();
    }
    return 0;
}

第一个错误意味着编译器不知道字符串的含义。我假设它指的是std::string。不仅要看第98行,还要看上面的行。但这是不正常的,;它应该构建。可能包含文件的顺序-你能显示实际的C++文件而不是错误列表。@ Pulf我编辑了我的问题,整个文件都是。你忘记了任何像头文件一样的文件吗?试着在包含之后添加包含。
// MySQL_Connection.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include <stdio.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#define DB_HOST_NAME "localhost"
#define DB_USERNAME "root"
#define DB_PASSWORD "Passw0rd"
#define DB_SCHEMA_NAME "TESTDB"

//#include "mysql_connection.h"

#include <cppconn/driver.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>

// The one and only application object

using namespace std;
using namespace sql;



int main(int argc, char * argv[])
{

    Driver *driver;
    Connection *con;
    ResultSet *rs;
    Statement *stmt;
    PreparedStatement  *pre_stmt;

    int id;
    char* name;
    char flag;
    cout << "Connecting to MySQL database...";

    /* Create a connection */
    driver = get_driver_instance();
    con = driver->connect(DB_HOST_NAME, DB_USERNAME, DB_PASSWORD);

    try
    {
        if ( con->isValid() ) /* This method is used to check that mysql connection is alive or not */
        {
        /* Connect to mysql database */
            con->setSchema(DB_SCHEMA_NAME);


            /* Creating statement for inserting data into test table */
            stmt = con->createStatement();
            stmt->execute("USE " DB_SCHEMA_NAME );
            stmt->execute("DROP TABLE IF EXISTS test");
            stmt->execute("CREATE TABLE test ( id INT, name VARCHAR(30) )");

            cout << "\nTable is created.";
            cout << "\n\n Below Operations are done by \"Statement.\"";

            stmt->execute("INSERT INTO test VALUES ( 1, 'Unnat' ) ");
            stmt->execute("INSERT INTO test VALUES ( 2, 'Kunal' ) ");
            stmt->execute("INSERT INTO test VALUES ( 3, 'Abhishek' ) ");
            stmt->execute("INSERT INTO test VALUES ( 4, 'Mithun' ) ");
            stmt->execute("INSERT INTO test VALUES ( 5, 'Kiran' ) ");

            cout << "\nData Inserted.";

            delete stmt;

            /* Creating statement for fetching data from test table*/
            stmt = con->createStatement();
            rs = stmt->executeQuery("SELECT * FROM test ORDER BY id ASC");

            cout << "ID\tNAME\n";
            cout << "--\t----\n";

            while ( rs->next() ) // next() will check weather next data is present or not
            {
                /*
                    * rs->getInt(x) : get the numbered column data, specified in parameter
                        [ NOTE ] : column number starts form 1, not 0.
                    * rs->getString ( "column-name" ) :  fetch data of given column in parameter
                */
                cout << rs->getInt(1) << rs->getString("name");
            }

            delete rs;
            delete stmt;

            /* Insert operation using PreparedStatement. */
            cout << "\nInsert operation using PreparedStatement.\n\n";

            do 
            {
                pre_stmt = con->prepareStatement("INSERT INTO test VALUES ( ?, ? ) ");

                cout << "ID : ";
                cin >> id;

                cout << "Name : ";
                cin >> name;

                pre_stmt->setInt ( 1, id );
                pre_stmt->setString( 2, name );

                cout << "Data Added.\n";

                cout << "\nDo you want to continue? [Y/N] :";
                cin >> flag;
            } while (flag == 'Y' || flag == 'y');

            delete pre_stmt;
        }
    }
    catch (exception e)
    {
        cout << "Error :";
        //cout << "Error on " << __LINE__ << " \n\t in ( " << __FUNCTION__ << " ) ";
        e.what();
    }
    return 0;
}