Jump to content
  • Advertisement
Sign in to follow this  
ankhd

std::string and formatting a string help

This topic is 3726 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I've looked up many std::string web pages but they all seem to avoid any talk about formatting a string like this Eg.sprintf_s(camloc, MAX_PATH, "Camera::Location::X = %f Y = %f Z = %f",pos.x, pos.y, pos.z); how can I do that with this. std::string mystring; mystring ??????????????

Share this post


Link to post
Share on other sites
Advertisement
If I'm reading right what you want to do, you want something like this:

std::stringstream mystring;
mystring << "Camera::Location::X = " << pos.x << " Y = " << pos.y << " Z = " << pos.z;

I haven't tested this and it's just a real quick, "this should work" response, so no guarantees (no guarantees I even understand what you want to do, for that matter).

Share this post


Link to post
Share on other sites
EDIT: too slow ;)


#include <sstream>

...

std::stringstream s;
s << "Camera::Location::X = "<<pos.x<<" Y = "<<pos.y<<" Z = "<<pos.z;

std::string str = s.str();





If you want something more similar to the printf-style of formatting, check out Boost Format.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!