How to convert an float into a std::string?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: How to convert an float into a std::string?

  1. #1
    Join Date
    Dec 2010
    Posts
    587

    How to convert an float into a std::string?

    I am working with a XML serializer.
    I wonder if I am creating a text element (xerces)
    But the value I am after is a float, how do I convert it into a std::string?
    Thanks
    Jack

  2. #2
    Join Date
    Dec 2010
    Posts
    587

    Re: How to convert an float into a std::string?

    Code:
    std::ostringstream ss;
    ss << v.x;
    std::string buff(ss.str());
    Errors here. I've included iostream and using namespace std;

  3. #3
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,699

    Re: How to convert an float into a std::string?

    Did you include <string> ?
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

  4. #4
    Join Date
    Dec 2010
    Posts
    587

    Re: How to convert an float into a std::string?

    Hi John,
    I've included and not included it, but it seems to be of a little differences.
    Thanks
    Jack

  5. #5
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,012

    Re: How to convert an float into a std::string?

    Quote Originally Posted by lucky6969b View Post
    Code:
    std::ostringstream ss;
    ss << v.x;
    std::string buff(ss.str());
    Errors here. I've included iostream and using namespace std;
    First google hit: http://www.cplusplus.com/reference/s...ostringstream/
    On the left side, under 'Reference' you see which header this is defined in.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center