stringstream 的简单用法

· · 个人记录

遇到类似于 P1020 [NOIP1999 提高组] 导弹拦截的恶心输入怎么办?

stringstream!!!

这玩意能通过以下方式读入一行数(不给数的数量)。

首先定义一个字符串(string 类型)。

string line;

然后把一行所有乱七八糟的东西全读入进来。

getline(cin,line);

定义一个 stringstream,并把上述读入的乱七八糟的东西的字符串赋值给定义的 stringstream。

stringstream sin(line);

最后是读入数组!

while (sin>>a[++n]);

More importantly,它需要头文件 sstream或 bits/stdc++.h!

没了。