我安裝了Visual Studio 2015 Update 2 Release Candidate,現在似乎遇到了一個使用sregex_token_iterator
的問題,目前爲止似乎工作正常。爲了驗證我試圖從cppreference.com下面的示例代碼(請注意,我改變了可變text
有在最後一個空格):Visual Studio 2015 Update 2中的regex_token_iterator問題RC
#include <iostream>
#include <regex>
int main() {
std::string text = "Quick brown fox ";
// tokenization (non-matched fragments)
// Note that regex is matched only two times: when the third value is obtained
// the iterator is a suffix iterator.
std::regex ws_re("\\s+"); // whitespace
std::copy(std::sregex_token_iterator(text.begin(), text.end(), ws_re, -1),
std::sregex_token_iterator(),
std::ostream_iterator<std::string>(std::cout, "\n"));
}
運行此給出以下論斷:
Debug Assertion Failed!
Program: C:\WINDOWS\SYSTEM32\MSVCP140D.dll
File: c:\program files (x86)\microsoft visual studio 14.0\vc\include\xstring
Line: 247
Expression: string iterators incompatible
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
是那Visual Studio STL實現中的一個bug或者是regex_token_iterator
的例子錯誤?
cppreference.com示例嚴格遵守標準,錯誤發生在C運行時而不是拋出異常,所以我確信它是STL實現中的一個錯誤。至少MSVC開發者非常聰明,可以爲這個預期的情況添加一個斷言。 – Youka
我建議使用boost正則表達式,STL正則表達式實現通常是buggy(至少對我來說),而切換到boost只需要改變命名空間。 – Youka