添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
c++中string和其他基本数据类型的转化总是需要自己实现,但是c++11给广大的c++程序员带来了福音,c++基础类型的相互转化变得非常简单。
  1. 其他类型 -> string
    std::string to_string( int value );
    std::string to_string( long value );
    std::string to_string( long long value );
    std::string to_string( unsigned value );
    std::string to_string( unsigned long value );
    std::string to_string( unsigned long long value );
    std::string to_string( float value );
    std::string to_string( double value );
    std::string to_string( long double value );
    例子:
    #include <iostream>
    #include <string>
    int main() 
    		double f = 23.43;
    		double f2 = 1e-9;
    		double f3 = 1e40;
    		double f4 = 1e-40;
    		double f5 = 123456789;
    		std::string f_str = std::to_string(f);
    		std::string f_str2 = std::to_string(f2); // Note: returns "0.000000"
    		std::string f_str3 = std::to_string(f3); // Note: Does not return "1e+40".
    		std::string f_str4 = std::to_string(f4); // Note: returns "0.000000"
    		std::string f_str5 = std::to_string(f5);
    		std::cout << "std::cout: " << f << '\n'
    							<< "to_string: " << f_str  << "\n\n"
    							<< "std::cout: " << f2 << '\n'
    							<< "to_string: " << f_str2 << "\n\n"
    							<< "std::cout: " << f3 << '\n'
    							<< "to_string: " << f_str3 << "\n\n"
    							<< "std::cout: " << f4 << '\n'
    							<< "to_string: " << f_str4 << "\n\n"
    							<< "std::cout: " << f5 << '\n'
    							<< "to_string: " << f_str5 << '\n';
    }
  2. string -> int
    int stoi( const std::string& str, std::size_t* pos = 0, int base = 10 );
    int stoi( const std::wstring& str, std::size_t* pos = 0, int base = 10 );
  3. string -> long
    long stol( const std::string& str, std::size_t* pos = 0, int base = 10 );
    long stol( const std::wstring& str, std::size_t* pos = 0, int base = 10 );
  4. string -> long long
    long long stoll( const std::string& str, std::size_t* pos = 0, int base = 10 );
    long long stoll( const std::wstring& str, std::size_t* pos = 0, int base = 10 );
  5. string -> unsigned long
    unsigned long stoul( const std::string& str, std::size_t* pos = 0, int base = 10 );
    unsigned long stoul( const std::wstring& str, std::size_t* pos = 0, int base = 10 );
  6. string -> unsigned long long
    unsigned long long stoull( const std::string& str, std::size_t* pos = 0, int base = 10 );
    unsigned long long stoull( const std::wstring& str, std::size_t* pos = 0, int base = 10 );
  7. string -> float
    float stof( const std::string& str, std::size_t* pos = 0 );
    float stof( const std::wstring& str, std::size_t* pos = 0 );
  8. string -> double
    double stod( const std::string& str, std::size_t* pos = 0 );
    double stod( const std::wstring& str, std::size_t* pos = 0 );
  9. string -> long double
    long double stold( const std::string& str, std::size_t* pos = 0 );
    long double stold( const std::wstring& str, std::size_t* pos = 0 );
1\基本 类型 string nt a = 100, b = 200; string A = to_ string (a) + to_ string (b);//100200 2\ string c string *   声明如下: const char * string ::data(); //以字符数组的形式返回字符串内容但不主动添加'\0' const char * string ::c_str(); ...
文章目录GO 类型 换及与C的 类型 类型 类型 断言其他 换bytes 、 string int erface string string 与unicode字符 互转 go和c 类型 装换 GO 类型 换及与C的 类型 类型 换 dst := float 32(src) var num int = 520 f32 := float 32(num) i64 := int 64(num) 注意:加入va...
npos : 18446744073709551615 size_type max : 18446744073709551615 size_t max : 18446744073709551615 uint64_t max : 18446744073709551615
WebRTC 源码下载 <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get C++ 之 auto推导遇到多态 C++ 之 std::numeric_limits 类模板