以下是關鍵代碼
/*
for (int i = 1; i <= n; i++)
{
res = mysql_query(&myCont, "INSERT INTO `i` (`id`, `name`, `age`, `subject`, `score`) VALUES ('3', 'C', '12', '英語', '100')");//查詢
}
*/ //模板
for (int i = 1; i <= n; i++)
{
int id; /*char name[10]*/; int age; /*char subject[10]*/; int score; string name; string subject;
cout << "intput id:"; cin >> id; cout << endl;
cout << "input name:"; getline(cin, name);
cout << "intput sge:"; cin >> age; cout << endl;
cout << "input subject:"; getline(cin, subject);
cout << "intput score:"; cin >> score; cout << endl;
res = mysql_query(&myCont, "INSERT INTO `i` (`id`, `name`, `age`, `subject`, `score`)VALUES (id, 'name', age, 'subject', score)");
//VALUES('3', 'C', '12', '英語', '100')");//查詢
}
res = mysql_query(&myCont, "INSERT INTO i
(id
, name
, age
, subject
, score
)VALUES (id, 'name', age, 'subject', score)");
現在問題就是這句怎麼改
用字符串拼接方式把變量組合sql語句字符串 然後執行