#include <stdio.h>
#include <iostream>
#include <string>
#include<Windows.h> // MultiByteToWideChar 等函數的所需標頭檔
using namespace std;
#include "sqlite\sqlite3.h"
int ImportData() // test
{
sqlite3* sqlite;
sqlite3_open("E:\\info.db", &sqlite); // info.db 事先有line這個table 和 line_name這個varchar這個欄位
char str [256] = "實驗";
WCHAR* strA;
int i= MultiByteToWideChar ( CP_ACP , 0 ,(char*) str ,-1 ,NULL,0);
strA = new WCHAR[i];
MultiByteToWideChar ( CP_ACP , 0 ,( char * ) str, -1, strA , i);
i= WideCharToMultiByte(CP_UTF8,0,strA,-1,NULL,0,NULL,NULL);
char *strB=new char[i]; //
即所需的類型
WideCharToMultiByte (CP_UTF8,0,strA,-1,strB,i,NULL,NULL);
char strsql[1024] = {0};
sprintf(strsql,"INSERT INTO line (line_name) VALUES ('%s')", strB);
sqlite3_stmt* stmt;
char** err = NULL;
int reterr;
sqlite3_exec(sqlite, strsql, NULL, NULL, err);
//strB即為所求
delete []strA;
delete []strB;
sqlite3_close(sqlite);
return 0;
}