我在将int 类型的数据压入一个string的时候该如何写啊? 比如说:
int a = 15;
int b = 16;
string name = "test"
string query = "insert into test values ('"+name+"','"+a+"','"+b+"')";但是我在编译的时候就提示错误,我的分析是我的int型的 a 和 b 在压入string类型的时候出错. 请帮忙看看应该如何写这个string 语句.是不是连接的时候出问题?
int a = 15;
int b = 16;
string name = "test"
string query = "insert into test values ('"+name+"','"+a+"','"+b+"')";但是我在编译的时候就提示错误,我的分析是我的int型的 a 和 b 在压入string类型的时候出错. 请帮忙看看应该如何写这个string 语句.是不是连接的时候出问题?
(2)string query = "insert into test values ('"+name+"',"+a+","+b+")"; 这种写法也报错.
使用string query = "insert into test values ('"+name+"',"+a+","+b+")"; 这种写法也报错:
1>------ Build started: Project: TDBServer, Configuration: Debug Win32 ------
1>Compiling...
1>DClient.cpp
1>e:\ricky\work files\filenew\program\gameserver\src\gamecore\object.h(62) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
1>e:\ricky\work files\filenew\program\gameserver\src\gamecore\object.h(105) : warning C4244: 'return' : conversion from 'uint16' to 'uint8', possible loss of data
1>e:\ricky\work files\filenew\program\gameserver\src\gamecore\tailmanager.h(27) : warning C4267: 'return' : conversion from 'size_t' to 'uint32', possible loss of data
1>e:\ricky\work files\filenew\program\gameserver\src\gamecore\buff.h(18) : warning C4355: 'this' : used in base member initializer list
1>e:\ricky\work files\filenew\program\gameserver\src\gamecore\worldsession.h(22) : warning C4172: returning address of local variable or temporary
1>e:\ricky\work files\filenew\program\gameserver\src\tdbserver\dclient.cpp(111) : warning C4267: 'argument' : conversion from 'size_t' to '_UInt32', possible loss of data
1>e:\ricky\work files\filenew\program\gameserver\src\tdbserver\dclient.cpp(132) : warning C4267: 'argument' : conversion from 'size_t' to '_UInt32', possible loss of data
1>e:\ricky\work files\filenew\program\gameserver\src\tdbserver\dclient.cpp(133) : warning C4267: '+=' : conversion from 'size_t' to 'uint32', possible loss of data
1>e:\ricky\work files\filenew\program\gameserver\src\tdbserver\dclient.cpp(171) : warning C4101: 'idx' : unreferenced local variable
1>e:\ricky\work files\filenew\program\gameserver\src\tdbserver\dclient.cpp(200) : error C2782: 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : template parameter '_Elem' is ambiguous
1> e:\program files\study tools\visual studio 2005\vc\include\string(61) : see declaration of 'std::operator +'
1> could be 'uint16'
1> or 'char'
1>e:\ricky\work files\filenew\program\gameserver\src\tdbserver\dclient.cpp(200) : error C2784: 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const _Elem *' from 'uint16'
1> e:\program files\study tools\visual studio 2005\vc\include\string(51) : see declaration of 'std::operator +'
1>e:\ricky\work files\filenew\program\gameserver\src\tdbserver\dclient.cpp(200) : error C2784: 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(const _Elem,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'uint16'
1> e:\program files\study tools\visual studio 2005\vc\include\string(41) : see declaration of 'std::operator +'
1>e:\ricky\work files\filenew\program\gameserver\src\tdbserver\dclient.cpp(200) : error C2784: 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(const _Elem *,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const _Elem *' from 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> e:\program files\study tools\visual studio 2005\vc\include\string(31) : see declaration of 'std::operator +'
1>e:\ricky\work files\filenew\program\gameserver\src\tdbserver\dclient.cpp(200) : error C2784: 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'uint16'
1> e:\program files\study tools\visual studio 2005\vc\include\string(21) : see declaration of 'std::operator +'
1>e:\ricky\work files\filenew\program\gameserver\src\tdbserver\dclient.cpp(200) : error C2784: 'std::_Vb_iterator<_MycontTy> std::operator +(_Vb_iterator<_MycontTy>::difference_type,std::_Vb_iterator<_MycontTy>)' : could not deduce template argument for 'std::_Vb_iterator<_MycontTy>' from 'uint16'
1> e:\program files\study tools\visual studio 2005\vc\include\vector(1800) : see declaration of 'std::operator +'
1>e:\ricky\work files\filenew\program\gameserver\src\tdbserver\dclient.cpp(200) : error C2784: 'std::_Vb_const_iterator<_MycontTy> std::operator +(_Vb_const_iterator<_MycontTy>::difference_type,std::_Vb_const_iterator<_MycontTy>)' : could not deduce template argument for 'std::_Vb_const_iterator<_MycontTy>' from 'uint16'
1> e:\program files\study tools\visual studio 2005\vc\include\vector(1695) : see declaration of 'std::operator +'
1>e:\ricky\work files\filenew\program\gameserver\src\tdbserver\dclient.cpp(200) : error C2784: 'std::_Vector_iterator<_Ty,_Alloc> std::operator +(_Vector_iterator<_Ty,_Alloc>::difference_type,std::_Vector_iterator<_Ty,_Alloc>)' : could not deduce template argument for 'std::_Vector_iterator<_Ty,_Alloc>' from 'uint16'
1> e:\program files\study tools\visual studio 2005\vc\include\vector(396) : see declaration of 'std::operator +'
1>e:\ricky\work files\filenew\program\gameserver\src\tdbserver\dclient.cpp(200) : error C2784: 'std::_Vector_const_iterator<_Ty,_Alloc> std::operator +(_Vector_const_iterator<_Ty,_Alloc>::difference_type,std::_Vector_const_iterator<_Ty,_Alloc>)' : could not deduce template argument for 'std::_Vector_const_iterator<_Ty,_Alloc>' from 'uint16'
1> e:\program files\study tools\visual studio 2005\vc\include\vector(264) : see declaration of 'std::operator +'
1>e:\ricky\work files\filenew\program\gameserver\src\tdbserver\dclient.cpp(200) : error C2784: 'std::_String_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_iterator<_Elem,_Traits,_Alloc>' from 'uint16'
1> e:\program files\study tools\visual studio 2005\vc\include\xstring(439) : see declaration of 'std::operator +'
1>e:\ricky\work files\filenew\program\gameserver\src\tdbserver\dclient.cpp(200) : error C2784: 'std::_String_const_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_const_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_const_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_const_iterator<_Elem,_Traits,_Alloc>' from 'uint16'
1> e:\program files\study tools\visual studio 2005\vc\include\xstring(299) : see declaration of 'std::operator +'
1>e:\ricky\work files\filenew\program\gameserver\src\tdbserver\dclient.cpp(200) : error C2784: 'std::reverse_iterator<_RanIt> std::operator +(_Diff,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'uint16'
1> e:\program files\study tools\visual studio 2005\vc\include\xutility(1847) : see declaration of 'std::operator +'
1>e:\ricky\work files\filenew\program\gameserver\src\tdbserver\dclient.cpp(200) : error C2676: binary '+' : 'std::basic_string<_Elem,_Traits,_Ax>' does not define this operator or a conversion to a type acceptable to the predefined operator
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
std::string name;
uint16 job;
uint16 sex;
uint16 photo;
cin >> name;
cin >> job;
cin >> sex;
cin >> photo;(1) std::string sqlInsert ="insert into players(Name, Job, Sex,Photo) values('"+name+"',"+job+","+sex+","photo")"; //c++编译错误
(1) std::string sqlInsert ="insert into players(Name, Job, Sex,Photo) values('"+name+"')"; //c++编译正确,虽然sql执行会出错但是在
C++ 的编译错误似乎不用来问了吧
(
Id int(4) auto_increment primary key,
Name varchar(20) not null,
Job smallint(2) not null default 1,
Sex smallint(2) not null default 1,
Photo smallint(2) not null default 1,
Email varchar(20)
)engine = MYISAM;
我的表中只有这么几列数据. 错误已经在上面提供了. 首先出现的是C++ 编译错误啊...
1>e:\ricky\work files\c++\c++primertest\testmysql\src\main.cpp(49) : error C2110: '+' : cannot add two pointers
现在你的C++语法错误,不是数据库本身的问题。
string query = "sting"+ 13;可以相连,不过 输出的结果并不是我想要的"sting13", 看来只能将int转换成string类型之后才能相连了...顺便请教:
(1)在mysql中使用select 得到的一个结果集中的int类型为什么都是string类型的呢? 不管数据库中存放的是什么数据都是string类型的吗?
(2)使用C++ 进行数据库操作的时候,为什么执行完一个存储过程之后,以后不管什么操作都不能执行呢? 而且错误编号是 2014. 如何设置?
是的, 返回的列都是 char*
应该没有这样问题,这个你需要具体分析你的代码了。