I've never seen this call to char()
as a function before. Where is this described and what does it mean? This usage is part of the example on this cppreference.com community wiki page: https://en.cppreference.com/w/cpp/string/basic_string/resize:
short_string.resize( desired_length + 3 );
std::cout << "6. After: \"";
for (char c : short_string) {
std::cout << (c == char() ? '@' : c); // <=== HERE ===
}
This wording in the description also doesn't make any sense to me and I don't understand what it's saying:
Initializes appended characters to
CharT()
.
Highlighted in context:
Adjacently related
- What motivated me to study the
std::string::resize()
method was trying to learn how to pre-allocate astd::string
for use in C function calls as achar*
buffer. This is possible by first pre-allocating thestd::string
by calling themy_string.resize()
function on it. Then, you can safely write into&my_string[0]
as a standardchar*
up to indexmy_string.size() - 1
. See also:
Update:
- 3.5 months after asking the original question, I was made aware of this question also: What does
int()
do in C++?
char
considered a class? If not, this question is certainly not a duplicate. Voting to re-open. – Phippenint()
,char()
,uint64_t()
, etc., which is the whole crux of this question. And, they are both closed. – Phippenchar() in c++
weren't very productive. – Phippenint()
. None ofwhat does char() mean c++
,what does uint8_t() mean c++
,what does int64_t() mean c++
,what does double() mean c++
,what does T() mean c++
, etc, produce similar useful results. – Phippen