Converting mysqlpp::String to C++ int
Ok, I'm relatively new to using th开发者_如何学Goe mysqlpp library that is used in Visual Studio to connect to a MySQL database and am having trouble trying to convert a vector of type mysqlpp::String to a vector of type int. Does anyone have any experience with mysqlpp and would mind helping me out a little? I've posted an example of what I'm basically trying to do below that appears in my code. Assume the vector futureItemsets is already populated and I just want to copy over the contents into an integer vector. Thanks for any help you can provide!
vector<int> timeFrameItemsets;
vector<mysqlpp::String> futureItemsets;
for(int j = 0; j < static_cast<int>(futureItemsets.size()); j++) {
timeFrameItemsets.push_back(futureItemsets[j]);
}
mysqlpp::String has operator int()
so your code snippet should work. What problem are you having with it?
If you want to be more explicit, you can use mysqlpp::String's conv function:
int i = futureItemsets[j].conv<int>(0);
timeFrameItemsets.push_back(i);
精彩评论