Formatting struct timespec

后端 未结 4 1060
余生分开走
余生分开走 2020-12-23 17:04

How to format struct timespec to string? This structure is returned e.g. by clock_gettime() on Linux gcc:

struct timespec {
    tim         


        
4条回答
  •  不知归路
    2020-12-23 17:41

    You could use a std::stringstream. You can stream anything into it:

    std::stringstream stream;
    stream << 5.7;
    stream << foo.bar;
    
    std::string s = stream.str();
    

    That should be a quite general approach. (Works only for C++, but you asked the question for this language too.)

提交回复
热议问题