So i have been doing some googling about and searching on this site, but i'm struggling to find an answer to the following code and hoping that someone with more knowledge of list initializer can help me with understanding what is going on.
int main() {
std::string t1 = {{}};
std::string t2 = {};
printf("%u ___ %u", "" == t1, "" == t2 );
while (true);
return 0;
}
outputs:
0 ___ 1
Can anyone explain what the difference between {} and {{}} is for this?
Thanks
std::string t1 = {{}};
"initialize a string with one element which is empty (0, since it's char, built in type)"
std::string t2 = {};
"initialize a string with an empty string"
Try adding these lines to have evidence of it:
std::cout << t1.size() << std::endl;
std::cout << (int)t1[0] << std::endl;
std::cout << t2.size() << std::endl;