如何在C ++ 11中使用wregex?

时间:2013-07-21 06:25:41

标签: regex visual-c++ c++11

我尝试使用正常的正则表达式,一切都很好,我切换到wregex进行搜索和Unicode字符之间的标记化时,它失败了,我无法理解为什么。
有人可以指出我在这里失踪了吗?

map<string, int> container;
wifstream file("ftest.txt"); 
wregex reg(_T("\\w+"));
wstring s=_T("");
while (file.good())
{
    file>>s;
    for ( wsregex_iterator it (s.cbegin(), s.cend(), reg),it_end; it != it_end; ++it)
    {
        container[(*it)[0]]++ ;
    }

}

我的文件内容是在波斯语中,例如:

بسم الله الرحمن الرحیم 
تست یک تست 2 . 2357 نفر آمار تست اولیه هرچی!!

这些是它产生的错误:

  

错误C2679:二进制'[':找不到右侧的操作符   'const std :: sub_match&lt; _BidIt&gt;'类型的操作数(或者没有   可接受的转换)

     

IntelliSense:没有运算符“[]”匹配这些操作数操作数类型   是:std :: map,   的std ::分配器&GT;&GT; [const   的std :: sub_match&GT;&GT;&GT; ]

1 个答案:

答案 0 :(得分:2)

s.begin()和s.end()应返回wstring迭代器(make s为wstring)。

这就是你如何在ifstream中使用wstring How to use std::ifstream to read in a binary file with a wide string path

地图也应为map<wstring, int>