2023-05-03 11:06:20 +02:00
== Why is this an issue?
2021-04-28 16:49:39 +02:00
Contrary to what you might believe, using the addition operator does not append an integral constant to a string. Adding a ``++char++`` or an integral to a string pointer does not append it to the string. What it does instead is incrementing the string pointer by a value defined by this ``++char++`` or integral.
2021-04-28 18:08:03 +02:00
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,cpp]
2021-04-28 16:49:39 +02:00
----
int a;
std::string str1 = "foo" + a; // Noncompliant
char[] b = "foo";
char* str2 = b + 'b'; // Noncompliant{code}
----
2023-05-03 11:06:20 +02:00
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,cpp]
2021-04-28 16:49:39 +02:00
----
int a;
std::string str1 = "foo" + std::to_string(a); // Compliant
std::string s = "foo";
std::string str2 = s + 'b'; // Compliant{code}
----
2021-04-28 18:08:03 +02:00
2021-09-20 15:38:42 +02:00
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== Message
adding "XXX" to a string pointer does not append to the string
2021-09-20 15:38:42 +02:00
endif::env-github,rspecator-view[]