我要插入int
和 string
从 C++ 程序到 mysql 表的值。
for (std::map < int, std::vector < std::string > >::iterator hit = three_highest.begin(); hit != three_highest.end(); ++hit) {
//std::cout << hit->first << ":";
for (std::vector < std::string >::iterator vit = (*hit).second.begin(); vit != (*hit).second.end(); vit++) {
std::cout << hit->first << ":";
std::cout << *vit << "\n";
我要插入 hit->first
和 *vit
.
我在这里看到了例子:OTL Example for mysql .它对我有用吗?
如何在我的系统中设置OTL环境?我需要安装它还是什么?
这是另一种方式的非常简单的示例。但是它直接
include <mysql.h>
我在我的系统中找不到。使用什么环境?
我使用的是 Linux - Ubuntu 环境。
最佳答案
在这里,我得到了如何将 c++ 与 mysql 连接:
首先从源代码编译了 c++ 连接器库,但过了一会儿我想我可能做错了什么所以我只是使用 apt 来获取它:
sudo apt-get install libmysqlcppconn-dev
所以我现在已经遇到这个问题一个星期了,我也对它感到非常沮丧。我刚刚终于能够构建一个除了登录 mysql 之外什么都不做的程序,我真的高兴得尖叫起来。这是我的资料,希望对您有所帮助。
我首先从源代码编译了 c++ 连接器库,但过了一会儿我想我可能做错了什么所以我只是使用 apt 来获取它:
sudo apt-get install libmysqlcppconn-dev
这是我的简单测试源文件“tester.cpp”
#include <stdlib.h>
#include <iostream>
#include <mysql_connection.h>
#include <driver.h>
#include <exception.h>
#include <resultset.h>
#include <statement.h>
using namespace sql;
int main(void){
sql::Driver *driver;
sql::Connection *con;
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306","root","YOURPASSWORD");
return 0;
}
最后是 g++ 编译命令:
sudo g++ -Wall -I/usr/include/cppconn -o testapp tester.cpp -L/usr/lib -lmysqlcppconn
关于c++ - 使用 OTL 库从 C++ 程序将数据插入 mysql 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18605751/