How to fix this error
/home/andi/Desktop/latihan/sqlite c++/sqlite insert.cpp:37:76: error: invalid operands of types ‘const char [53]’ and ‘char [50]’ to binary ‘operator+’
This is the code. I hope my code is readable, sorry for my poor English
# include <stdio.h>
# include <iostream>
# include <sqlite3.h>
# include <stdlib.h>
using namespace std;
int main(void)
{
sqlite3 *conn;
sqlite3_stmt *res;
int error = 0;
int rec_count = 0;
const char *errMSG;
const char *tail;
char sql_lite[900]=" ";
int x,number;
char name[50];
char username[50];
char password[50];
error = sqlite3_open("data.dat", &conn);
if (error)
{
printf("Can not open database");
}
printf("Enter the number of data to be inserted\n");
scanf("%d",&x);
for(number=x;number>0;number--)
{
cout<<"name : ";cin>>name;
cout<<"username : ";cin>>username;
cout<<"password : ";cin>>password;
}
sprintf(sql_lite, "INSERT INTO login (name,username,password) VALUES ('"+ username + "','" + name + "','" + password +"');");
error = sqlite3_exec(conn, sql_lite, 0, 0, 0);
error = sqlite3_prepare_v2(conn, "SELECT * FROM login order by No",1000, &res, &tail);
if (error != SQLITE_OK)
{
printf("We did not get any data!");
exit(0);
}
printf("=======================================\n");
while (sqlite3_step(res) == SQLITE_ROW)
{
printf("%d|", sqlite3_column_int(res, 0));
printf("%s|", sqlite3_column_text(res, 1));
printf("%s|", sqlite3_column_text(res, 2));
printf("%s|", sqlite3_column_text(res, 3));
printf("%u\n", sqlite3_column_int(res, 4));
rec_count++;
}
printf("=======================================\n");
printf("We received %d records.\nTotal rows=%d\n",rec_count,SQLITE_ROW);
sqlite3_finalize(res);
sqlite3_close(conn);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire