包含头文件 <string>

功能:将括号内的 数字 转化为 字符串

to_string( idata )

#include <string>
#include <iostream>
int main()
{
    std::string s="the pi is ";
    std::cout << s << std::endl; 

    s += std:: to_string(3.141592653589);
    std::cout << s << std::endl;

    s.clear();
    s = std:: to_string(2.7+3.14159);
    std:: cout << s << std::endl;
    
    system("pause");
    return 0;
}

 

 运行结果:

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐