How can I convert a string into an integer? I tried this: totalMins += atoi(MovieRecord->getMinutes()); Which I think only works for C-strings, and I tried this: totalMins += static_cast<int>(MovieRecord->getMinutes()); which I think only works for converting an int to a double or something similar.
rookieNeedsHelp 0 Newbie Poster
Recommended Answers
Jump to PostI tend to go for the
stringstream
class instead, because it is more "C++-style" and it has more options in terms of formatted input. For a simple string-to-int mechanism, I would just do:std::stringstream(MovieRecord->getMinutes()) >> totalMins;
Or, in two steps:
std::stringstream ss(MovieRecord->getMinutes()); …
All 4 Replies
Labdabeta 182 Posting Pro in Training Featured Poster
L7Sqr 227 Practically a Master Poster
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster
rookieNeedsHelp 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.