What's wrong with this line?

There's this one line of code that's giving me trouble and I can't seem to figure out what I'm doing wrong. Any suggestions?

 
if(tok2.value.at(0) == '(' )


Basically, I just want to check if a string has parentheses (tok2 is a struct, and value is its string component).
Hi
what does tok2.value.at(0) return? could you check it out ?
Last edited on
wouldn't it be better to use the [] operator instead?

 
if( tok2.value[0] == '(' )


Also, what is the error you're getting? All you said, really, is that it's not working.
Last edited on
Perhaps value is an empty string? You can try to catch an exception and see what is wrong.
You could do something like this this:
1
2
3
4
5
6
7
#include <algorithm>
//...

int match[] = {'(',')'};
std::string::iterator it = std::find_first_of(tok2.value.begin(),tok2.value.end(),match, match +2);
	if(it != tok2.value.end())
		std::cout << "FOUND" << std::endl;  //You know you have found it. 
Topic archived. No new replies allowed.