Operator[] function use in Strings

I know this may make me look stupid, (aren't we all) but I was attempting to use the operator[] function to find a character in a string by it's position, and I think I might have used it in the wrong way...did I?
1
2
string str = "5+6"
cout << str.operator[1]
Why not just do str[1]?
the normal way to use it:

1
2
string str = "5+6";
cout << str[1];
I'm sorry I didn't tummychow, I'm just very new to this whole language (know some others tho).
Thanks Disch and tummy
I'm not trying to be mean. I just don't see the point of writing out the full qualification of the operator. I mean, what would the point of overloading an operator be, if it didn't make anything more efficient or intuitive?
I don't know what you just said... I was just trying to figure out how to refer to the position of a character in a string. I still don't know how to use operator and I probably wont need it for my simple programs anyway.
If you're using the standard lib String class, you can refer to a specific element of the string as Disch said with str[1], or also with str.at(1) which throws an exception when accessing an element outside the string boundaries, which you can choose to handle or not. But that's probably not something to worry about now.

The notation you were using was explicity calling the overloaded [] operator function. You just messed up a bit at the end. But that's a silly notation to ever use :)
cout << str.operator[](1);
if your ever in doubt about how to use something, you can simply check the API on this site. Just about everything has examples with it.
http://cplusplus.com/reference/string/string/operator%5B%5D/
Topic archived. No new replies allowed.