我从https://dev.mysql.com/downloads/connector/cpp/下载了mysql C ++连接器包。我写了一个使用它的简单程序。以下是代码。此代码实际上是https://dev.mysql.com/doc/connector-cpp/en/connector-cpp-examples-complete-example-1.html
的示例代码的一部分#include <cppconn/driver.h>
int main(void)
{
sql::Driver *driver;
sql::Connection *con;
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
delete con;
return 0;
}
运行它会产生以下错误消息:
[frank@arch mysql-connector-c++]$ ./a.out
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Aborted (core dumped)
为什么不起作用?