我只是想使用 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;
}
最佳答案
It just keeps throwing the PM when the PM is separated from 00 by a space.
这不是 throw 。 PM
只是不存在于 str1
中,因为 std::cin
也使用空格作为分隔符。替换
cin >> str1;
与
std::getline(std::cin, str1);
关于c++ - 在 boost::char_separator 中使用空格作为分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17131040/