CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    May 2007
    Location
    Valencia, Spain ( Europe )
    Posts
    73

    integer to std::string

    Hi!

    Does anyone know how to "write" a integer into a std::string?

    Thank you very much for your time!

  2. #2
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: integer to std::string

    use a strstream and just "<<" it....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  3. #3
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,725

    Re: integer to std::string

    1) see the FAQ : http://www.codeguru.com/forum/showthread.php?t=231056

    2) strstream ... isn't that deprecated ?

  4. #4
    Join Date
    May 2007
    Location
    Valencia, Spain ( Europe )
    Posts
    73

    Re: integer to std::string

    I got it. Thanks TheCPUWizard.

    By the way, this is the function:

    std::string CCLInformationColladaFile::IntegerToString(int i) {
    std:stringstream o;
    if (!(o << i)) return "ERROR";
    return o.str();
    }

  5. #5
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: integer to std::string

    Quote Originally Posted by Philip Nicoletti
    2) strstream ... isn't that deprecated ?
    Not to the best of my knowledge...where did you here of the possibility????
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  6. #6
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,725

    Re: integer to std::string

    I thought that it was already deprecated (in C++ 98)

    Somewhere in Annex D ... I do not have a copy of the
    standard on this computer.

  7. #7
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: integer to std::string

    There is mention of it even in the draft... http://anubis.dkuug.dk/jtc1/sc22/open/n2356/

    Have to look into the final when I get back to the office....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  8. #8
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Resolved Re: integer to std::string

    http://msdn2.microsoft.com/en-us/lib...f4(VS.80).aspx
    The classes in <strstream> are deprecated. Consider using the classes in <sstream> instead.
    My hobby projects:
    www.rclsoftware.org.uk

  9. #9
    Join Date
    May 2007
    Location
    Valencia, Spain ( Europe )
    Posts
    73

    Re: integer to std::string

    Thanks a lot.

    I will try to change it.

  10. #10
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,725

    Re: integer to std::string

    Quote Originally Posted by riruilo
    Thanks a lot.

    I will try to change it.

    The code you posted already uses stringstream (which
    is not deprecated).

  11. #11
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: integer to std::string

    Quote Originally Posted by Philip Nicoletti
    The code you posted already uses stringstream (whichis not deprecated).
    No, his post is using the "smiley stream" class.. std:stringstream

    It is for generating "embarassing" output...
    Last edited by TheCPUWizard; May 16th, 2007 at 03:52 PM.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  12. #12
    Join Date
    May 2007
    Location
    Valencia, Spain ( Europe )
    Posts
    73

    Re: integer to std::string

    Hahahahaha

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured