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

前端 未结 13 1127
不思量自难忘°
不思量自难忘° 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:50

    Use this function...

        #include
        template 
        std::string to_string(T value)
        {
          //create an output string stream
          std::ostringstream os ;
    
          //throw the value into the string stream
          os << value ;
    
          //convert the string stream into a string and return
          return os.str() ;
        }
    
        //you can also do this
        //std::string output;
        //os >> output;  //throw whats in the string stream into the string
    

提交回复
热议问题