Conversion of string values

Source: Internet
Author: User

[Cpp]
// Wang zhiquan
 
# Ifndef _ StringHelper _ H __
# Define _ StringHelper _ H __
 
# Include <string>
# Include <sstream>
 
# Define iToStdS (v) ValueToString <int> (v). str ()
# Define fToStdS (v) ValueToString <float> (v). str ()
# Define dToStdS (v) ValueToString <double> (v). str ()
 
# Define StdSToI (v) StringToValue <int> (v). value ()
# Define StdSToF (v) StringToValue <float> (v). value ()
# Define StdSToD (v) StringToValue <double> (v). value ()
 
// Convert numeric values to strings
Template <typename T>
Class ValueToString
{
Public:
 
ValueToString (T v)
{
Std: stringstream strem;
Strem <v;
_ Str = strem. str ();
}
 
Std: string & str ()
{Return _ str ;}
 
Private:
Std: string _ str;
};
 
// Convert string to numeric value
Template <typename T>
Class StringToValue
{
Public:
 
StringToValue (const std: string & s)
{
Std: stringstream strem (s );
Strem> _ val;
}
 
T value ()
{
Return _ val;
}
 
Private: www.2cto.com
 
T _ val;
};
 
# Endif
Author: xuhongwei0411

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.