如何在c++中获取空格前和空格后的值
How to grab values before space and after a space in c++
对于正在工作的项目,我想在空格前和空格后抓取文本。
为了找到空间,我使用isspace
方法,任何关于如何完成
与命令中提到的0x499602D2一样,您可以使用std::stringstream
从字符串中读取,就像使用任何其他流(如std::cin
)一样:
#include <sstream>
#include <iostream>
#include <string>
int main()
{
int a, b;
std::stringstream ss(std::stringstream::in | std::stringstream::out);
ss << "12 14";
ss >> a;
ss >> b;
std::cout << a << std::endl;
std::cout << b << std::endl;
return 0;
}
这很好的一点是,如果你知道如何使用std::cin
或任何其他流,你就知道如何使用stringstream
,所以你可以根据需要调整这个例子。
相关文章:
- 从 stdio 获取一行空格分隔的整数,而不知道它们是多少 (C++)
- 有没有办法在 c++ 中获取带有空格的完整字符串?
- 获取由空格分隔的未知大小的单行输入,并将其存储到整数数组中
- 无法在同一行上获取输出,在 C++ 中两个输出之间有空格
- 在 c++ 中获取 2 个空格之间的字符串
- 无法获取包含C++空格的输入
- 使用scanf()在数组中获取字符(不与空格分开)
- C++ 从带有 t 和空格的字符串中获取标记
- 如何获取不以空格结尾的字符串的输入
- C ++拆分字符串并获取空格之后的部分
- 是否有一个WinAPI可以从带有可选空格和其他参数的命令行获取文件名
- 无法在前面有多余空格的情况下获取要打印的数组.只有第一个值会用空格打印
- 如何获取我的区域设置的空格字符串?
- 拆分字符串以仅获取数字数组(转义空白和空格)
- 如何使用 scanf 从用户输入中获取字符串 ( char * ),由双引号分隔并包含空格
- 读取并获取值 BTW 空格和另一个字符
- 获取线,以读取具有空格和逗号分隔的字符串
- 如何以包含空格的字符串形式获取输入
- 在按空格时获取用户输入
- 单独获取字符,包括空格