使用空格作为boost::char_separator中的分隔符
Using space as delimiter in boost::char_separator
我只是想用Boost标记一些时间。输入5:00 PM
,输出<5> <00> <PM>
。问题是,我已经尝试了各种各样的东西,但它只输出<5> <00>
。然而,如果我输入5:00PM
,我得到的输出是<5> <00PM>
。我如何使boost接受空间作为令牌(旁边:)?当PM和00之间有空格分隔时,它会继续抛出PM。
#include "stdafx.h"
#include <iostream>
#include <boost/tokenizer.hpp>
#include <string>
#include <stdlib.h>
#include <boost/algorithm/string.hpp>
using namespace std;
int main(){
string str1;
cin >> str1;
typedef boost::tokenizer<boost::char_separator<char> >
tokenizer;
boost::char_separator<char> sep(":t ");
string t1 (str1);
tokenizer tokens1(t1, sep);
for (tokenizer::iterator tok_iter = tokens1.begin();
tok_iter != tokens1.end(); tok_iter++)
{cout << "<" << *tok_iter << "> ";}
system("pause");
return 0;
}
当PM与00之间有空格分隔时,它会继续抛出PM。
这不是投掷。PM
在str1
中不存在,因为std::cin
也使用空间作为分隔符。替换
cin >> str1;
std::getline(std::cin, str1);
相关文章:
- 当用户键入分隔符时,停止getline()输入
- 为什么在逗号分隔符上下文中将预增量的结果强制转换为void
- 如何在 c++ 中使用 ',' 作为 getline 分隔符
- 带有多个字符分隔符的正则表达式
- 使用 char 分隔符解析C++中的字符串,但将可重复的字符保留为每个解析的子字符串 (C++ STL) 中的分隔符
- 字符串开头的分隔符
- 尝试将 c 字符串数组与分隔符连接起来
- 正则表达式以匹配数字的重复模式,后跟任何类型的分隔符?
- 根据新的行分隔符从字符串中删除子字符串
- 同一分隔符之间的多个子字符串
- 通过分隔符分隔包含 UTF-16 BE 文本的uint8_t数组
- 字符串流分隔符
- 如何在 std::getline 中自定义分隔符
- getline() 上的分隔符无法正常工作
- 示例代码中使用分隔符将 std::string 拆分为 std::vector 的范围问题
- C++使用分隔符读取文件
- 使用连续分隔符和空最后一个字符进行拆分
- 到达分隔符时跳到文本文件的下一行
- 使用空格分隔符从文本文件将对象读入数组
- 使用正则表达式c++从单词和分隔符之间的字符串中提取所有子字符串