Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3042

Unexpected result when assigning character to std::string or MFC CString

$
0
0
Please can someone explain what I'm seeing here? I expected the same result, a compiler error, in both situations. What's different when the variables are part of the struct? Sorry if the answer is blatantly obvious and I'm just not seeing it...

Code:

std::string str_one = 'a'; // Compiler error
CString str_two = 'a'; // Compiler error

struct MyStruct
{
    std::string str_one;
    CString str_two;
};

MyStruct my_struct;
my_struct.str_one = 'a'; // OK
my_struct.str_two = 'a'; // OK


Viewing all articles
Browse latest Browse all 3042

Trending Articles