C++ What should I use to save formatted in a string variable like sprintf()?


C++ What should I use to save formatted in a string variable like sprintf()?
I'm used to programming in C but now I needed to use C++ for a project, and I need to save some text into a string, the code I would have used in C would have been
sprintf(pathFotosLimpias, "CleanPictures/Picture_T%d_%d", pictureNumber, templateNumber);
Or something like that, but pathFotosLimpias is a string so it doesn't work and I can't find how to save it as a sting, I think there is a boost function which does something similar to what I need but I can't figure out what exactly should I do, can someone explain what I need and maybe give me an example on how to use it?
Thank you.
Update: It is apparently a cv::String from opencv, I'm a bit more confused now.
sprintf
std::strings
std::ostringstream
In response to your edit, I don't know anything about the
cv::String
type, but it is probably incompatible with use of sprintf
. If you are wedded to using that function, then you need to output into a C-style string (i.e. a char array) and then convert that to the type you need. But tjis is not exactly optimal.– Neil Butterworth
9 mins ago
cv::String
sprintf
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
You cannot really use
sprintf
withstd::strings
. Usestd::ostringstream
instead.– Neil Butterworth
19 mins ago