Rule A27-0-4 (required, implementation, automated)
C-style strings shall not be used.
Rationale
It is required that an underlying buffer for a C-style string needs to be of sufficient size to hold character data and a null terminator. In addition, a C-style string implies all other disadvantages of built-in arrays (see A18-1-1 in section 6.18.1). Using std:: string provides correct memory allocation, copying, gradual expansion and iteration. It is self-explanatory in terms of ownership and offers more readable interface.
Example
// $Id: A27-0-4.cpp 311495 2018-03-13 13:02:54Z michal.szczepankiewicz $
#include <iostream>
#include <string>
#include <list>
void F1()
{
std::string string1;
std::string string2;
std::cin >> string1 >> string2; // Compliant - no buffer overflows
}
std::list<std::string> F2(const std::string& terminator)
{
std::list<std::string> ret;
//read a single word until it is different from the given terminator sequence
for (std::string s; std::cin >> s && s != terminator; )
{
ret.push_back(s);
}
return ret;
}
See also
C++ Core Guidelines [11]: SL.str.1: Use std::string to own character sequences.