简体   繁体   中英

Converting mysqlpp::String to C++ int

Ok, I'm relatively new to using the 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM