나는 Boost.Regex를 사용하여 단어와 숫자의 문자열을 구문 분석했습니다. 이것은 내가 지금까지 가지고있는 것입니다 :Boost.Regex를 사용하여 스트림을 파싱 할 수 있습니까?
#include <iostream>
#include <string>
#include <boost/foreach.hpp>
#include <boost/regex.hpp>
#include <boost/range.hpp>
using namespace std;
using namespace boost;
int main()
{
regex re
(
"("
"([a-z]+)|"
"(-?[0-9]+(\\.[0-9]+)?)"
")"
);
string s = "here is a\t list of Words. and some 1239.32 numbers to 3323 parse.";
sregex_iterator m1(s.begin(), s.end(), re), m2;
BOOST_FOREACH (const match_results<string::const_iterator>& what, make_iterator_range(m1, m2)) {
cout << ":" << what[1].str() << ":" << what.position(1) << ":" << what.length(1) << endl;
}
return 0;
}
정규 표현식이 문자열이 아닌 스트림에서 구문 분석하도록 지시하는 방법이 있습니까? 반복자를 사용할 수 있어야합니다.
문자열을''a ""b "'단지'+'없이 연결할 수 있습니까? 와우, 나는 그 표준을 본 적이 없다. –
예, C 및 C++에서는 항상 표준이었습니다. 이런 식의 문자열 상수는 연결할 수 있지만 C++ std :: strings는 연결할 수 없습니다. – Ferruccio