⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xstring_i.hpp

📁 经典的string 函数库学习资料
💻 HPP
字号:
/** * @file xstring_I.hpp * @brief 字符串的包装,模版函数和内联函数的实现 * @author 泥偶 * @since  2003-08-29 * @date   2004-08-28 */#ifndef XSTRING_I_HPP#define XSTRING_I_HPP#include <iomanip>#include <sstream>namespace x{//----------------------------------------------------------------------------    /**    类型T需要重载移位运算符<tt>operator <<()</tt>和<tt>operator <<()</tt>来处    理流操作    @bug 使用g++ version 3.0.4编译的时候,传入很大的double型数据(超过1e39)    会造成Segementation fault;这有可能是g++的缺陷    @see to()     */    template<typename T>    xstring::xstring(const T& v)    {        std::stringstream stream;        std::string str;        // neo patch 2003-09-25        stream.setf(std::ios::fixed);        stream << v;        stream >> str;        this->assign(str);    }//----------------------------------------------------------------------------    /**    类型T需要重载移位运算符<tt>operator <<()</tt>和<tt>operator <<()</tt>来处理流操作    @code  * xstring str = "1805";  * int i;  * float f;  * i = str.to<int>();      // i -> 1805  * f = str.to<float>();    // f -> 1805.0    @endcode    @see xstring()     */    template<typename T>    T xstring::to(void) const    {        std::stringstream stream;        T v;        stream << *this;        stream >> v;        return v;    }    /// 转换成其它类型,std::string特化版本    template<>    inline std::string xstring::to<std::string>(void) const    {        return static_cast<std::string>(*this);    }    /// 转换成其它类型,xstring特化版本    template<>    inline xstring xstring::to<xstring>(void) const    {        return *this;    }//----------------------------------------------------------------------------    /**    非常量版本重载    @return 按值返回    @see to()     */    inline xstring xstring::toString(void)    {        return *this;    }    /**    常量版本重载    @return 返回自身的引用    @see to()     */    inline const xstring& xstring::toString(void) const    {        return *this;    }//----------------------------------------------------------------------------}   // namespace x#endif  // ifndef XSTRING_I_HPP

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -