How To Convert a Number To std::string

There are many methods available. You can use itoa, ltoa etc. to convert numbers to char*. However the following method using stringstream can convert any type of number to std::string.


#include 
using namespace std;
int main()
{
   int No = 140;  // Or you can use float No = 10.5f
   stringstream StrStream;
   StrStream << No;
   string MyString = StrStream.str();
   return 0;
}
[/sourcecode]

 
  The resulting MyString contains the value of No as string.  

Click to see how to convert string to number

Click to see how to convert CString to std::string

Advertisements

3 Responses to How To Convert a Number To std::string

  1. […] Click to see how to convert number to string […]

  2. hiv testing says:

    Pretty portion of content. I just stumbled upon your site
    and in accession capital to claim that I get actually loved account
    your weblog posts. Any way I will be subscribing for your feeds and
    even I fulfillment you get right of entry to persistently fast.

  3. Clint says:

    There is a second return path to the pump through a pipe fitted to the bottom of
    the pool is available for your client’s help. There are
    sometimes mixed messages within Property Management Long Island as to who holds
    responsibility for different areas in the United States are governed by the lease agreement from
    the tenant. You can property management long island check to with the local state or municipal law.
    Tenant pays propane and electric.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: