I was taught string::at
in school, but by exploring the string library I saw string::operator[]
, which I was never shown before.
I'm now using operator[]
and haven't used at
since, but what is the difference?
Here is some sample code:
std::string foo = "my redundant string has some text";
std::cout << foo[5];
std::cout << foo.at(5);
They are essentially the same in terms of output, but are there some subtle differences I'm not aware of?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…