substr

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
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 '#'.
So i should do like:
string s = res.substr(res.find("#"), res.length()-res.find("#")) ?
That would work, yes. Assuming that there is a # in the string.
I'm pretty sure if the 2nd arg of substr is longer then the string, you just get the entire string.

The function will also not work correctly if the passed string does not contain a space or '#'.


That is the issue I believe.
Topic archived. No new replies allowed.