In C++, what is the difference between the string.at(i)
method and string[i]
? What are the advantages or disadvantages to using one or the other?
#include <iostream>
#include <string>
int main() {
std::string s = "Hello World";
std::cout << s.at(1) << endl;
std::cout << s[1] << endl;
}
As far as I know, they do the same thing, but I don't know much about C++.