Aug 24, 2010 at 8:03pm Aug 24, 2010 at 8:03pm UTC
Hi, when calling this function:
1 2 3 4 5
string getChannel(string res)
{
string s = res.substr(res.find("#" ), res.length());
return s.substr(1, s.find(" " ));
}
the program terminates without giving any reason.
Last edited on Aug 24, 2010 at 8:11pm Aug 24, 2010 at 8:11pm UTC
Aug 25, 2010 at 5:24am Aug 25, 2010 at 5:24am UTC
That's because you're trying to extract more characters than there are if # is not the first character of res.
The function will also not work correctly if the passed string does not contain a space or '#'.
Aug 26, 2010 at 12:43am Aug 26, 2010 at 12:43am UTC
So i should do like:
string s = res.substr(res.find("#"), res.length()-res.find("#")) ?
Aug 26, 2010 at 6:08pm Aug 26, 2010 at 6:08pm UTC
That would work, yes. Assuming that there is a # in the string.