How do I convert a long to a string in C++?

后端 未结 12 1262
慢半拍i
慢半拍i 2020-12-09 07:12

How do I convert a long to a string in C++?

12条回答
  •  粉色の甜心
    2020-12-09 08:00

    The way I typically do it is with sprintf. So for a long you could do the following assuming that you are on a 32 bit architecture:

    char buf[5] = {0}; // one extra byte for null    
    sprintf(buf, "%l", var_for_long);
    

提交回复
热议问题