mercredi 4 novembre 2020

My split function doesnt work, error C2664,

So this is supposed to split string and turn it into list:

std::list<std::string> strSplit(std::string::iterator begin, std::string::iterator end, char c) {
    while(std::find(begin, end, c) != end) *std::find(begin, end, c) = '\0';
    return std::list<std::string>(begin, end);
}

But compiler throws this error:

Error: C2664    
'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string
(const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &)':
 cannot convert argument 1 from 'char' to 'std::initializer_list<_Elem>'

And double click redirects to xmemory0 line: 881

...
template<class _Objty,
class... _Types>
static void construct(_Alloc&, _Objty * const _Ptr, _Types&&... _Args)
{   // construct _Objty(_Types...) at _Ptr
::new (const_cast<void *>(static_cast<const volatile void *>(_Ptr)))
    _Objty(_STD forward<_Types>(_Args)...);
}
...

Aucun commentaire:

Enregistrer un commentaire