Why is .c_str() not adding '' at the end of a string?2019 Community Moderator ElectionHow do you construct a std::string with an embedded null?How do I iterate over the words of a string?Why can templates only be implemented in the header file?Why is “using namespace std” considered bad practice?string::c_str queryEasiest way to convert int to string in C++Why are elementwise additions much faster in separate loops than in a combined loop?Why does changing 0.1f to 0 slow down performance by 10x?Why is reading lines from stdin much slower in C++ than Python?Why is it faster to process a sorted array than an unsorted array?Why should I use a pointer rather than the object itself?
US to Europe trip with Canada layover- is 52 minutes enough?
How does Dispel Magic work against Stoneskin?
What is the likely impact on flights of grounding an entire aircraft series?
Humans have energy, but not water. What happens?
My story is written in English, but is set in my home country. What language should I use for the dialogue?
Deleting missing values from a dataset
Best approach to update all entries in a list that is paginated?
Is "history" a male-biased word ("his+story")?
Can infringement of a trademark be pursued for using a company's name in a sentence?
Who is our nearest neighbor
Latest web browser compatible with Windows 98
How to make readers know that my work has used a hidden constraint?
infinitive telling the purpose
Want to switch to tankless, but can I use my existing wiring?
Decoding assembly instructions in a Game Boy disassembler
Prove that the total distance is minimised (when travelling across the longest path)
Do I need to leave some extra space available on the disk which my database log files reside, for log backup operations to successfully occur?
validation vs test vs training accuracy, which one to compare for claiming overfit?
Are there situations where a child is permitted to refer to their parent by their first name?
Plywood subfloor won't screw down in a trailer home
What is the difference between "shut" and "close"?
Is it illegal in Germany to take sick leave if you caused your own illness with food?
Counter-example to the existence of left Bousfield localization of combinatorial model category
Why do Australian milk farmers need to protest supermarkets' milk price?
Why is .c_str() not adding '' at the end of a string?
2019 Community Moderator ElectionHow do you construct a std::string with an embedded null?How do I iterate over the words of a string?Why can templates only be implemented in the header file?Why is “using namespace std” considered bad practice?string::c_str queryEasiest way to convert int to string in C++Why are elementwise additions much faster in separate loops than in a combined loop?Why does changing 0.1f to 0 slow down performance by 10x?Why is reading lines from stdin much slower in C++ than Python?Why is it faster to process a sorted array than an unsorted array?Why should I use a pointer rather than the object itself?
When running this code I get "Hello Worldaaa", but according to the job of the .c_str() function, the string a should be "Hello World" and string b should be "Hello Worldaaa" so "aaa" should not show up in the output.
#include <bits/stdc++.h>
using namespace std;
int main()
string a = "Hello World";
a = a.c_str();
string b = a + string("aaa");
cout << b;
return 0;
c++ c-strings
add a comment |
When running this code I get "Hello Worldaaa", but according to the job of the .c_str() function, the string a should be "Hello World" and string b should be "Hello Worldaaa" so "aaa" should not show up in the output.
#include <bits/stdc++.h>
using namespace std;
int main()
string a = "Hello World";
a = a.c_str();
string b = a + string("aaa");
cout << b;
return 0;
c++ c-strings
3
"Returns a pointer to a null-terminated character array with data equivalent to those stored in the string." It does, but using it in thestd::string operator+(const char*, const std::string&)ignores the terminating''character to produce the result.
– πάντα ῥεῖ
Mar 6 at 17:46
2
it's not actually.c_str(), it's actually the constructor that's confusing you.
– Mooing Duck
Mar 6 at 17:47
Possible duplicate of How do you construct a std::string with an embedded null?
– πάντα ῥεῖ
Mar 6 at 18:00
add a comment |
When running this code I get "Hello Worldaaa", but according to the job of the .c_str() function, the string a should be "Hello World" and string b should be "Hello Worldaaa" so "aaa" should not show up in the output.
#include <bits/stdc++.h>
using namespace std;
int main()
string a = "Hello World";
a = a.c_str();
string b = a + string("aaa");
cout << b;
return 0;
c++ c-strings
When running this code I get "Hello Worldaaa", but according to the job of the .c_str() function, the string a should be "Hello World" and string b should be "Hello Worldaaa" so "aaa" should not show up in the output.
#include <bits/stdc++.h>
using namespace std;
int main()
string a = "Hello World";
a = a.c_str();
string b = a + string("aaa");
cout << b;
return 0;
c++ c-strings
c++ c-strings
asked Mar 6 at 17:42
Mayar KaroutMayar Karout
293
293
3
"Returns a pointer to a null-terminated character array with data equivalent to those stored in the string." It does, but using it in thestd::string operator+(const char*, const std::string&)ignores the terminating''character to produce the result.
– πάντα ῥεῖ
Mar 6 at 17:46
2
it's not actually.c_str(), it's actually the constructor that's confusing you.
– Mooing Duck
Mar 6 at 17:47
Possible duplicate of How do you construct a std::string with an embedded null?
– πάντα ῥεῖ
Mar 6 at 18:00
add a comment |
3
"Returns a pointer to a null-terminated character array with data equivalent to those stored in the string." It does, but using it in thestd::string operator+(const char*, const std::string&)ignores the terminating''character to produce the result.
– πάντα ῥεῖ
Mar 6 at 17:46
2
it's not actually.c_str(), it's actually the constructor that's confusing you.
– Mooing Duck
Mar 6 at 17:47
Possible duplicate of How do you construct a std::string with an embedded null?
– πάντα ῥεῖ
Mar 6 at 18:00
3
3
"Returns a pointer to a null-terminated character array with data equivalent to those stored in the string." It does, but using it in the
std::string operator+(const char*, const std::string&) ignores the terminating '' character to produce the result.– πάντα ῥεῖ
Mar 6 at 17:46
"Returns a pointer to a null-terminated character array with data equivalent to those stored in the string." It does, but using it in the
std::string operator+(const char*, const std::string&) ignores the terminating '' character to produce the result.– πάντα ῥεῖ
Mar 6 at 17:46
2
2
it's not actually
.c_str(), it's actually the constructor that's confusing you.– Mooing Duck
Mar 6 at 17:47
it's not actually
.c_str(), it's actually the constructor that's confusing you.– Mooing Duck
Mar 6 at 17:47
Possible duplicate of How do you construct a std::string with an embedded null?
– πάντα ῥεῖ
Mar 6 at 18:00
Possible duplicate of How do you construct a std::string with an embedded null?
– πάντα ῥεῖ
Mar 6 at 18:00
add a comment |
3 Answers
3
active
oldest
votes
Yes, you are right regarding
std::string::c_str.
Indeed,
Returns a pointer to a null-terminated character array with data equivalent to those stored in the string.
However, there are a few considerations which probably misleading you.
First of all, the statement:
a = a.c_str();
is semantically a no-operation.
You get the const char* (i.e. "Hello World") and assign it to a.
However a is a std::string, it is a class designed to abstract a "string type" in C++. It handles automatically the '', transparently. The user is not supposed to care about the managing of it1.
The trick is inside std::string::operator=(const char*).
Replaces the contents with those of null-terminated character string pointed to by s as if by assign(s, Traits::length(s)).
The last point, about string concatenation.
a + string("aaa");
As previously, in this case, the operator std::string::operator+ will handle the ''.
Shortly, it behaves like:
"Hello World" + "aaa" ===> "Hello Worldaaa"
It will care about the "inner ''" returning a conforming null-terminated string.
1 Unless he/she is playing with the internal memory.
Really, the point needs to be made that in a "NUL-terminated string", the NUL terminator is not considered part of the string's data. It is merely an end-of-string indicator. That is,"Hello World"is a different string from"Hello World"; the latter has an embedded NUL character which is part of the actual string.
– Nicol Bolas
Mar 6 at 18:24
add a comment |
That would be unintuitive. Remember that the terminating null character wasn't explicitly used by the user. Syntax of the language added it.
It will create a lot of confusion if the result of "abcd" + "xyz" ends up being "abcdxyz" instead of the intuitive result - "abcdxyz".
In C and C++, concatenating two strings implies ignoring the terminating null character of the first string in the resultant string. Take a look at the documentation of strcat. It is explicit about the null character while the documentation of std::string::operator+ isn't.
The really interesting part is what would be the workaround to store thecharacter explicitely in astd::string.
– πάντα ῥεῖ
Mar 6 at 17:52
@πάνταῥεῖ, I am sure people with a more computer science/programming language theory bent of mind have thought about it. Not me.
– R Sahu
Mar 6 at 17:57
1
Yes they did
– πάντα ῥεῖ
Mar 6 at 17:59
add a comment |
Not quite...
Let's take a look at this line:
a = a.c_str();
You have an std::string that you're trying to assign a const char* to. So you'll be using overload (3) of the std::string assignment operator. But this doesn't magically change the type of a. In other words, we still have an std::string!
So that line doesn't actually modify the value of a at all.
Then you use the operator+ to add two std::string's together. This will result in another std::string that is the first with the second appended, which is exactly what you have!
It's not clear to me what you're trying to accomplish here, but if you created a c-string with those values:
const char cstr[] = "Hello Worldaaa";
And tried to print it, you'd see exactly what you're expecting.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55029196%2fwhy-is-c-str-not-adding-0-at-the-end-of-a-string%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Yes, you are right regarding
std::string::c_str.
Indeed,
Returns a pointer to a null-terminated character array with data equivalent to those stored in the string.
However, there are a few considerations which probably misleading you.
First of all, the statement:
a = a.c_str();
is semantically a no-operation.
You get the const char* (i.e. "Hello World") and assign it to a.
However a is a std::string, it is a class designed to abstract a "string type" in C++. It handles automatically the '', transparently. The user is not supposed to care about the managing of it1.
The trick is inside std::string::operator=(const char*).
Replaces the contents with those of null-terminated character string pointed to by s as if by assign(s, Traits::length(s)).
The last point, about string concatenation.
a + string("aaa");
As previously, in this case, the operator std::string::operator+ will handle the ''.
Shortly, it behaves like:
"Hello World" + "aaa" ===> "Hello Worldaaa"
It will care about the "inner ''" returning a conforming null-terminated string.
1 Unless he/she is playing with the internal memory.
Really, the point needs to be made that in a "NUL-terminated string", the NUL terminator is not considered part of the string's data. It is merely an end-of-string indicator. That is,"Hello World"is a different string from"Hello World"; the latter has an embedded NUL character which is part of the actual string.
– Nicol Bolas
Mar 6 at 18:24
add a comment |
Yes, you are right regarding
std::string::c_str.
Indeed,
Returns a pointer to a null-terminated character array with data equivalent to those stored in the string.
However, there are a few considerations which probably misleading you.
First of all, the statement:
a = a.c_str();
is semantically a no-operation.
You get the const char* (i.e. "Hello World") and assign it to a.
However a is a std::string, it is a class designed to abstract a "string type" in C++. It handles automatically the '', transparently. The user is not supposed to care about the managing of it1.
The trick is inside std::string::operator=(const char*).
Replaces the contents with those of null-terminated character string pointed to by s as if by assign(s, Traits::length(s)).
The last point, about string concatenation.
a + string("aaa");
As previously, in this case, the operator std::string::operator+ will handle the ''.
Shortly, it behaves like:
"Hello World" + "aaa" ===> "Hello Worldaaa"
It will care about the "inner ''" returning a conforming null-terminated string.
1 Unless he/she is playing with the internal memory.
Really, the point needs to be made that in a "NUL-terminated string", the NUL terminator is not considered part of the string's data. It is merely an end-of-string indicator. That is,"Hello World"is a different string from"Hello World"; the latter has an embedded NUL character which is part of the actual string.
– Nicol Bolas
Mar 6 at 18:24
add a comment |
Yes, you are right regarding
std::string::c_str.
Indeed,
Returns a pointer to a null-terminated character array with data equivalent to those stored in the string.
However, there are a few considerations which probably misleading you.
First of all, the statement:
a = a.c_str();
is semantically a no-operation.
You get the const char* (i.e. "Hello World") and assign it to a.
However a is a std::string, it is a class designed to abstract a "string type" in C++. It handles automatically the '', transparently. The user is not supposed to care about the managing of it1.
The trick is inside std::string::operator=(const char*).
Replaces the contents with those of null-terminated character string pointed to by s as if by assign(s, Traits::length(s)).
The last point, about string concatenation.
a + string("aaa");
As previously, in this case, the operator std::string::operator+ will handle the ''.
Shortly, it behaves like:
"Hello World" + "aaa" ===> "Hello Worldaaa"
It will care about the "inner ''" returning a conforming null-terminated string.
1 Unless he/she is playing with the internal memory.
Yes, you are right regarding
std::string::c_str.
Indeed,
Returns a pointer to a null-terminated character array with data equivalent to those stored in the string.
However, there are a few considerations which probably misleading you.
First of all, the statement:
a = a.c_str();
is semantically a no-operation.
You get the const char* (i.e. "Hello World") and assign it to a.
However a is a std::string, it is a class designed to abstract a "string type" in C++. It handles automatically the '', transparently. The user is not supposed to care about the managing of it1.
The trick is inside std::string::operator=(const char*).
Replaces the contents with those of null-terminated character string pointed to by s as if by assign(s, Traits::length(s)).
The last point, about string concatenation.
a + string("aaa");
As previously, in this case, the operator std::string::operator+ will handle the ''.
Shortly, it behaves like:
"Hello World" + "aaa" ===> "Hello Worldaaa"
It will care about the "inner ''" returning a conforming null-terminated string.
1 Unless he/she is playing with the internal memory.
answered Mar 6 at 17:56
Biagio FestaBiagio Festa
5,11821239
5,11821239
Really, the point needs to be made that in a "NUL-terminated string", the NUL terminator is not considered part of the string's data. It is merely an end-of-string indicator. That is,"Hello World"is a different string from"Hello World"; the latter has an embedded NUL character which is part of the actual string.
– Nicol Bolas
Mar 6 at 18:24
add a comment |
Really, the point needs to be made that in a "NUL-terminated string", the NUL terminator is not considered part of the string's data. It is merely an end-of-string indicator. That is,"Hello World"is a different string from"Hello World"; the latter has an embedded NUL character which is part of the actual string.
– Nicol Bolas
Mar 6 at 18:24
Really, the point needs to be made that in a "NUL-terminated string", the NUL terminator is not considered part of the string's data. It is merely an end-of-string indicator. That is,
"Hello World" is a different string from "Hello World"; the latter has an embedded NUL character which is part of the actual string.– Nicol Bolas
Mar 6 at 18:24
Really, the point needs to be made that in a "NUL-terminated string", the NUL terminator is not considered part of the string's data. It is merely an end-of-string indicator. That is,
"Hello World" is a different string from "Hello World"; the latter has an embedded NUL character which is part of the actual string.– Nicol Bolas
Mar 6 at 18:24
add a comment |
That would be unintuitive. Remember that the terminating null character wasn't explicitly used by the user. Syntax of the language added it.
It will create a lot of confusion if the result of "abcd" + "xyz" ends up being "abcdxyz" instead of the intuitive result - "abcdxyz".
In C and C++, concatenating two strings implies ignoring the terminating null character of the first string in the resultant string. Take a look at the documentation of strcat. It is explicit about the null character while the documentation of std::string::operator+ isn't.
The really interesting part is what would be the workaround to store thecharacter explicitely in astd::string.
– πάντα ῥεῖ
Mar 6 at 17:52
@πάνταῥεῖ, I am sure people with a more computer science/programming language theory bent of mind have thought about it. Not me.
– R Sahu
Mar 6 at 17:57
1
Yes they did
– πάντα ῥεῖ
Mar 6 at 17:59
add a comment |
That would be unintuitive. Remember that the terminating null character wasn't explicitly used by the user. Syntax of the language added it.
It will create a lot of confusion if the result of "abcd" + "xyz" ends up being "abcdxyz" instead of the intuitive result - "abcdxyz".
In C and C++, concatenating two strings implies ignoring the terminating null character of the first string in the resultant string. Take a look at the documentation of strcat. It is explicit about the null character while the documentation of std::string::operator+ isn't.
The really interesting part is what would be the workaround to store thecharacter explicitely in astd::string.
– πάντα ῥεῖ
Mar 6 at 17:52
@πάνταῥεῖ, I am sure people with a more computer science/programming language theory bent of mind have thought about it. Not me.
– R Sahu
Mar 6 at 17:57
1
Yes they did
– πάντα ῥεῖ
Mar 6 at 17:59
add a comment |
That would be unintuitive. Remember that the terminating null character wasn't explicitly used by the user. Syntax of the language added it.
It will create a lot of confusion if the result of "abcd" + "xyz" ends up being "abcdxyz" instead of the intuitive result - "abcdxyz".
In C and C++, concatenating two strings implies ignoring the terminating null character of the first string in the resultant string. Take a look at the documentation of strcat. It is explicit about the null character while the documentation of std::string::operator+ isn't.
That would be unintuitive. Remember that the terminating null character wasn't explicitly used by the user. Syntax of the language added it.
It will create a lot of confusion if the result of "abcd" + "xyz" ends up being "abcdxyz" instead of the intuitive result - "abcdxyz".
In C and C++, concatenating two strings implies ignoring the terminating null character of the first string in the resultant string. Take a look at the documentation of strcat. It is explicit about the null character while the documentation of std::string::operator+ isn't.
edited Mar 6 at 17:59
answered Mar 6 at 17:49
R SahuR Sahu
168k1292191
168k1292191
The really interesting part is what would be the workaround to store thecharacter explicitely in astd::string.
– πάντα ῥεῖ
Mar 6 at 17:52
@πάνταῥεῖ, I am sure people with a more computer science/programming language theory bent of mind have thought about it. Not me.
– R Sahu
Mar 6 at 17:57
1
Yes they did
– πάντα ῥεῖ
Mar 6 at 17:59
add a comment |
The really interesting part is what would be the workaround to store thecharacter explicitely in astd::string.
– πάντα ῥεῖ
Mar 6 at 17:52
@πάνταῥεῖ, I am sure people with a more computer science/programming language theory bent of mind have thought about it. Not me.
– R Sahu
Mar 6 at 17:57
1
Yes they did
– πάντα ῥεῖ
Mar 6 at 17:59
The really interesting part is what would be the workaround to store the
character explicitely in a std::string.– πάντα ῥεῖ
Mar 6 at 17:52
The really interesting part is what would be the workaround to store the
character explicitely in a std::string.– πάντα ῥεῖ
Mar 6 at 17:52
@πάνταῥεῖ, I am sure people with a more computer science/programming language theory bent of mind have thought about it. Not me.
– R Sahu
Mar 6 at 17:57
@πάνταῥεῖ, I am sure people with a more computer science/programming language theory bent of mind have thought about it. Not me.
– R Sahu
Mar 6 at 17:57
1
1
Yes they did
– πάντα ῥεῖ
Mar 6 at 17:59
Yes they did
– πάντα ῥεῖ
Mar 6 at 17:59
add a comment |
Not quite...
Let's take a look at this line:
a = a.c_str();
You have an std::string that you're trying to assign a const char* to. So you'll be using overload (3) of the std::string assignment operator. But this doesn't magically change the type of a. In other words, we still have an std::string!
So that line doesn't actually modify the value of a at all.
Then you use the operator+ to add two std::string's together. This will result in another std::string that is the first with the second appended, which is exactly what you have!
It's not clear to me what you're trying to accomplish here, but if you created a c-string with those values:
const char cstr[] = "Hello Worldaaa";
And tried to print it, you'd see exactly what you're expecting.
add a comment |
Not quite...
Let's take a look at this line:
a = a.c_str();
You have an std::string that you're trying to assign a const char* to. So you'll be using overload (3) of the std::string assignment operator. But this doesn't magically change the type of a. In other words, we still have an std::string!
So that line doesn't actually modify the value of a at all.
Then you use the operator+ to add two std::string's together. This will result in another std::string that is the first with the second appended, which is exactly what you have!
It's not clear to me what you're trying to accomplish here, but if you created a c-string with those values:
const char cstr[] = "Hello Worldaaa";
And tried to print it, you'd see exactly what you're expecting.
add a comment |
Not quite...
Let's take a look at this line:
a = a.c_str();
You have an std::string that you're trying to assign a const char* to. So you'll be using overload (3) of the std::string assignment operator. But this doesn't magically change the type of a. In other words, we still have an std::string!
So that line doesn't actually modify the value of a at all.
Then you use the operator+ to add two std::string's together. This will result in another std::string that is the first with the second appended, which is exactly what you have!
It's not clear to me what you're trying to accomplish here, but if you created a c-string with those values:
const char cstr[] = "Hello Worldaaa";
And tried to print it, you'd see exactly what you're expecting.
Not quite...
Let's take a look at this line:
a = a.c_str();
You have an std::string that you're trying to assign a const char* to. So you'll be using overload (3) of the std::string assignment operator. But this doesn't magically change the type of a. In other words, we still have an std::string!
So that line doesn't actually modify the value of a at all.
Then you use the operator+ to add two std::string's together. This will result in another std::string that is the first with the second appended, which is exactly what you have!
It's not clear to me what you're trying to accomplish here, but if you created a c-string with those values:
const char cstr[] = "Hello Worldaaa";
And tried to print it, you'd see exactly what you're expecting.
edited Mar 6 at 17:53
answered Mar 6 at 17:50
scohe001scohe001
8,15212342
8,15212342
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55029196%2fwhy-is-c-str-not-adding-0-at-the-end-of-a-string%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
"Returns a pointer to a null-terminated character array with data equivalent to those stored in the string." It does, but using it in the
std::string operator+(const char*, const std::string&)ignores the terminating''character to produce the result.– πάντα ῥεῖ
Mar 6 at 17:46
2
it's not actually
.c_str(), it's actually the constructor that's confusing you.– Mooing Duck
Mar 6 at 17:47
Possible duplicate of How do you construct a std::string with an embedded null?
– πάντα ῥεῖ
Mar 6 at 18:00