小编Den*_*ang的帖子

为什么 stringstream ss(s) 与 ss << s 不同?

当我尝试使用 stringstream 时

#include <iostream>
#include <string>
#include <sstream>

int main() {
    std::string s = "Hello World Test";
    std::stringstream ss(s);

    std::string a, b;
    ss >> a >> b;
    std::cout << a << ' ' << b << std::endl; // Hello World

    ss << " Why Not";
    ss >> a >> b;
    std::cout << a << ' ' << b << std::endl; // Still Hello World

    std::string c, d;
    std::stringstream tt;
    tt << s;

    tt >> c >> d;
    std::cout << …
Run Code Online (Sandbox Code Playgroud)

c++ string constructor stringstream bidirectional

3
推荐指数
1
解决办法
124
查看次数

标签 统计

bidirectional ×1

c++ ×1

constructor ×1

string ×1

stringstream ×1