getline和stringstream

yuanheci 2024年03月09日 235次浏览

<sstream> 定义了三个类:istringstream、ostringstream 和 stringstream,分别用来进行流的输入、输出和输入输出操作。本文以 stringstream 为主,介绍流的输入和输出操作。

#include <bits/stdc++.h>
using namespace std;


void solve(){
	string s;
	getline(cin, s);
	stringstream ss(s);
	string ns;
	while(ss >> ns) cout << ns << endl;
}

int main(){
	int _ = 1;
	while(_ -- ) solve();
	return 0;
}