Hello I'm writing this method. I want it to extract from a given buffer a portion that is in a given place. I have a string like this something=one;something=two
and I want to get "one"
This is my idea :
static std::string Utils::getHeader( unsigned char * buffer)
{
std::string *str = new std::string(buffer);
std::size_t b_pos = str->find("=");
std::size_t a_pos = str->find(";");
return str->substr((a_pos + 1) ,(b_pos + 1));
}
but on eclipse I get this error in reference to the std::string
substr
method
Invalid arguments ...
Candidates are:
std::basic_string<char,std::char_traits<char>,std::allocator<char>> substr(?, ?)
Can someone explain me why I get this error and how I can fix it?
The code should probably look like:
substr
takes a starting position and a length. Maybe something like:And then,
return str.substr(start, length);
.I'm not certain of the
a_pos + 1
andb_pos + 1
is correct, though. Be certain that's what you want.Ok, assuming you know that the input string is formatted as you mentioned you probably want something like this: