Static Analysis Problem Type Reference
The C++ basic string package is being used inefficiently.
The C++ standard template library defines a number of string operators. Some operators, such as string concatenation (+), tend to create and destroy temporary objects. This warning message is used to point out an alternative way to compute the same result more efficiently, by reducing the number of temporaries required.
|
ID |
Code Location |
Description |
|---|---|---|
|
1 |
Call site |
The place where the inefficient operation was found. |
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char **argv)
{
string a, b(argv[1]), c(argv[2]);
a = b + c; // better is (a = b), a += c; or (a = b) += c;
cout << b << " + " << c << " = " << a;
return 0;
}