このスレッドにあるメソッドを使用して文字列を分割しようとしていますが、それをwstringに適合させようとしています。しかし、私は奇妙なエラーに遭遇しました。コードを確認してください:
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;
int main(void)
{
wstring str(L"Börk börk");
wistringstream iss(str);
vector<wstring> tokens;
copy(istream_iterator<wstring>(iss), // I GET THE ERROR HERE
istream_iterator<wstring>(),
back_inserter< vector<wstring> >(tokens));
return 0;
}
正確なエラーメッセージは次のとおりです。
error: no matching function for call to 'std::istream_iterator<std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >, char, std::char_traits<char>, int>::istream_iterator(std::wistringstream&)'
iss
渡されたもの(istringstreamではなくwistringstream)を使用してistream_iteratorをインスタンス化できないと言っていると思います。これは、XCodeとGCC4.2を使用するMac上にあります。そして、AFAIKにはwistring_iteratorなどはありません。
wstring以外のバージョンを使用している場合は完全に機能します。ご覧のとおり、宣言を、、 s、およびを使用するように変更しwstring
、wistringstream
ワイドvector<wstring>
バージョンを使用するようにすべてを置き換えました。
これを引き起こす原因と、なぜwstring-versionを受け入れないのですか?