Tring to convert str string for use in std :: getline delimiter

im trying to take the value of std::string and use it as a separator in std::getline() but there is no mater, what am I doing, the compiler gives me an error. this is what i am trying to do:

 std::stringstream ss(s); std::string item; std::string delim ="&&="; int ssize = delim.size(); int newssize = ssize+1; char del[SSIZE]; // also here when i try gives error strcpy(del,delim.c_str()); char * delrr[1024] = delim.c_str(); //gives error while(std::getline(ss,item,delrr)) { elems.push_back(item); } 

the im get error is always related to the const char * conversion.

  error C2440: 'initializing' : cannot convert from 'const char *' to 'char *[1024]' 1> There are no conversions to array types, although there are conversions to references or pointers to arrays 1>.\UT.cpp(179) : error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : expects 2 arguments - 3 provided 1> d:\Program Files\Microsoft Visual Studio 9.0\VC\include\string(527) : see declaration of 'std::getline' 1>.\UT.cpp(179) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::stringstream' 1> d:\Program Files\Microsoft Visual Studio 9.0\VC\include\string(475) : see declaration of 'std::getline' 1>.\UT.cpp(179) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::stringstream' 1> d:\Program Files\Microsoft Visual Studio 9.0\VC\include\string(475) : see declaration of 'std::getline' 1>.\UT.cpp(179) : error C2782: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : template parameter '_Elem' is ambiguous 1> d:\Program Files\Microsoft Visual Studio 9.0\VC\include\string(475) : see declaration of 'std::getline' 1> could be 'char **' 1> or 'char' 

UPDATE:
found the answer: How to make string tokenization in C ++? http://www.codeproject.com/Articles/23198/C-String-Toolkit-StrTk-Tokenizer

+9
c ++ string split
source share
2 answers

The third argument to getline () is a character, not an array of characters. Watch this . You cannot use this function if you need multiple delimiters or a multiple character delimiter.

Use find () and substr ().

+3
source share

std :: string :: c_str () gives you a pointer to an array of characters. To populate an array of characters with the results of a call to c_str() , you need to use strcpy() or strncpy() , since they actually copy the C style string.

Also, you declared delrr as an array of 1024 characters, not 1024 characters, is that really the intention?

+3
source share

All Articles