2017-09-21 3 views
-2

私のデータベースに文字列を挿入するのはこのようなものですが、どのようにcharまたはintを挿入できますか? charのデータベースにint/charを挿入する

string us,pw,sc; 
cout<<"enter us: "<<endl; cin>>us; 
cout<<"enter pw: "<<endl; cin>>pw; 
cout<<"enter sc: "<<endl; cin>>sc; 

string query="insert into users(Username,Password,Seccode) values('"+us+"','"+pw+"','"+sc"')"; 

const char* q = query.c_str(); 

qstate = mysql_query(conn,q); 
+1

['std :: to_string'](http://en.cppreference.com/w/cpp/string/basic_string/to_string)および/または[' std :: stringstream'](http:// en。 cppreference.com/w/cpp/io/basic_stringstream) – NathanOliver

+1

常にユーザーの入力を消毒してください! – rak007

+2

Preparedステートメントも使用してください。おそらくそれ以上の問題はありません。 (文字列変換もsanatizationもありません) – SteakOverflow

答えて

0

あなたはcharとして変数cを持っている場合、あなたは文字列

string(1, c) 

にキャストするためにこれを使用して、あなたはintとしてiを持っている場合

std::to_string(i) 
をキャストするためにこれを使用することができます
関連する問題