Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't instantiate an istring_iterator using a wistringstream
    text
    copied!<p>I'm trying to split a string using the method found in <a href="https://stackoverflow.com/questions/236129/how-to-split-a-string/237280#237280">this thread</a>, but I'm trying to adapt it to a wstring. However, I have stumbled upon a weird error. Check the code:</p> <pre><code>#include &lt;iostream&gt; #include &lt;sstream&gt; #include &lt;string&gt; #include &lt;vector&gt; #include &lt;algorithm&gt; #include &lt;iterator&gt; using namespace std; int main(void) { wstring str(L"Börk börk"); wistringstream iss(str); vector&lt;wstring&gt; tokens; copy(istream_iterator&lt;wstring&gt;(iss), // I GET THE ERROR HERE istream_iterator&lt;wstring&gt;(), back_inserter&lt; vector&lt;wstring&gt; &gt;(tokens)); return 0; } </code></pre> <p>The exact error message is:</p> <pre><code>error: no matching function for call to 'std::istream_iterator&lt;std::basic_string&lt;wchar_t, std::char_traits&lt;wchar_t&gt;, std::allocator&lt;wchar_t&gt; &gt;, char, std::char_traits&lt;char&gt;, int&gt;::istream_iterator(std::wistringstream&amp;)' </code></pre> <p>I think it is saying that it can't instantiate the istream_iterator using the passed <code>iss</code> (which is a <strong>w</strong>istringstream instead of a istringstream). This is on a Mac using XCode and GCC 4.2. And AFAIK there is no wistring_iterator or anything like that.</p> <p>It works perfectly when I'm using the non-wstring version. As you might see I have changed the declarations to use <code>wstring</code>, <code>wistringstream</code>s and <code>vector&lt;wstring&gt;</code>, just replaced everything to use the wide version.</p> <p>What could cause this and why won't it accept the wstring-version?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload