c++中使用stringstream 连接字符串

//使用stringstream 连接字符串
#include <sstream>
#include <iostream>
// 
int main(){
    std::stringstream ss;

    //支持 c风格字符串,数值类型和其他支持<<操作符的类型
    ss << 1.618 << ", " << 66 << " haha";

    //转换为 string类型
    std::string str = ss.str();
    std::cout<<str<<std::endl;
}

运行结果

4.5, 4 whatever

发布了60 篇原创文章 · 获赞 10 · 访问量 3712

猜你喜欢

转载自blog.csdn.net/sinat_18811413/article/details/104441448