to_string is not a member of std, says g++ (mingw)

前端 未结 13 1336
不思量自难忘°
不思量自难忘° 2020-11-22 05:41

I am making a small vocabulary remembering program where words would would be flashed at me randomly for meanings. I want to use standard C++ library as Bjarne Stroustroup t

13条回答
  •  故里飘歌
    2020-11-22 05:53

    #include 
    #include 
    
    namespace patch
    {
        template < typename T > std::string to_string( const T& n )
        {
            std::ostringstream stm ;
            stm << n ;
            return stm.str() ;
        }
    }
    
    #include 
    
    int main()
    {
        std::cout << patch::to_string(1234) << '\n' << patch::to_string(1234.56) << '\n' ;
    }
    

    do not forget to include #include

提交回复
热议问题