Yes, there is one major difference: using .at()
does a range check on index passed and throws an exception if it’s over the end of the string while operator[]
just brings undefined behavior in that situation.
More Related Contents:
- Getting a segmentation error when printing my array of strings
- The array index doesnt show the character [closed]
- Pointer to string with spaces [closed]
- How do I tokenize a string in C++?
- std::cin input with spaces?
- C++ performance challenge: integer to std::string conversion
- std::string to char*
- Why can’t the switch statement be applied on strings?
- How do I create a random alpha-numeric string in C++?
- How to convert string to char array in C++?
- How to convert std::string to LPCSTR?
- What makes more sense – char* string or char *string? [duplicate]
- C/C++: Optimization of pointers to string constants
- Why are string literals const?
- Why does C++ allow an integer to be assigned to a string?
- Proper way to copy C strings
- Why are strings in C++ usually terminated with ‘\0’?
- invalid conversion from ‘const char*’ to ‘char’
- String to enum in C++
- writing directly to std::string internal buffers
- What is the proper function for comparing two C-style strings?
- How to read entire stream into a std::string?
- Counting the number of occurrences of a string within a string
- C++: Can a macro expand “abc” into ‘a’, ‘b’, ‘c’?
- Converting bool to text in C++
- Do I have to use #include beside ?
- Fastest way to Convert String to Binary?
- Should I return std::strings?
- Copying non null-terminated unsigned char array to std::string
- Getline keeps on getting newline character. How can I avoid this?