C++ 从std::string转换为SAString
我正在使用SQLAPI++将值插入到我的SQL数据库中,我正在尝试从国际象棋游戏中提取动作,并将其作为字符串插入数据库中的动作表中,就像这样(action_id=1,action_name=e4)。这是我的密码:C++ 从std::string转换为SAString,c++,sql,sqlapi++,C++,Sql,Sqlapi++,我正在使用SQLAPI++将值插入到我的SQL数据库中,我正在尝试从国际象棋游戏中提取动作,并将其作为字符串插入数据库中的动作表中,就像这样(action_id=1,action_name=e4)。这是我的密码: int main() { SAConnection con; SACommand cmd; try { con.Connect("test","tester","tester", SA_SQLServer_Client);
int main()
{
SAConnection con;
SACommand cmd;
try
{
con.Connect("test","tester","tester", SA_SQLServer_Client);
cmd.setConnection(&con);
std::ifstream pgnfile("sample.pgn");
pgn::GameCollection games;
pgnfile >> games;
for(pgn::GameCollection::iterator itr=games.begin();itr!=games.end();itr++)
{
pgn::Game game = *itr;
pgn::MoveList move_list=game.moves();
for(pgn::MoveList::iterator itr2=move_list.begin();itr2!=move_list.end();itr2++)
{
pgn::Move move=*itr2;
cmd.setCommandText("insert into actions (action_id,action_name) values (:1,:2)");
cmd.Param(1).setAsLong() = 1;
cmd.Param(2).setAsString() = move.black().str(); // the line that cause the error
}
}
}
}
问题就在这方面:
cmd.Param(2).setAsString() = move.black().str();
它无法从std::string转换为SAString!那么,您能告诉我如何将std::string转换为SAString吗?我不知道您特定的
SAString
类,但我相信应该可以从C样式的const char*
字符串(例如SAString(“Connie”)
)构造这样的字符串对象
给定一个std::string
你可以调用它的c_str
方法来获得这样一个c风格的字符串,它可能被用来构造你的SAString
因此,在方法调用序列中:
假设str
返回一个std::string
,我将添加对c_str
的调用:
... = move.black().str().c_str();
非常感谢,你的回答很有帮助!!问题解决了:)是的,我是stackOverflow的新手:)非常感谢:)
... = move.black().str().c_str();