C & C++

C & C++

Made by DeepSource

Indirect subscript for STL containers CXX-C2016

Style
Minor
Autofix

Found a subscript expressions on the STL container that can be further simplified directly using subscript operator.

For instance in case of string where you may call string.data() over directly indexing the std::string.

To fix, consider subscripting directly over container type rather than getting a pointer first.

Bad Practice

std::string s = "...";
int i = 0;
char c = s.data()[i];  // can be simplified to char c = s[i];

Recommended

std::string s = "...";
int i = 0;
char c = s[i];