easyloggingpp icon indicating copy to clipboard operation
easyloggingpp copied to clipboard

对char类型支持有缺陷,请确认

Open yanchenyuvip opened this issue 3 years ago • 3 comments

char type=2;

LOG(INFO)<<"type="<<type; //output is false! type=
LOG(INFO)<<"type="<<(u_char)type; //output is true! type=2

yanchenyuvip avatar Mar 30 '21 06:03 yanchenyuvip

It use std::stringstream or std::wstringsteam to format, ref to this. you can test use this:

    std::stringstream ss;
    ss << static_cast<int>(type) << " vs " << type;
    std::cout << ss.str();

LOG(INFO)<<"type="<<type; //output is false! type=

this is not output empty, because the ascii char 2 is control char.

SnorlaxGengar avatar Apr 07 '21 03:04 SnorlaxGengar

It use std::stringstream or std::wstringsteam to format, ref to this. you can test use this:

    std::stringstream ss;
    ss << static_cast<int>(type) << " vs " << type;
    std::cout << ss.str();

LOG(INFO)<<"type="<<type; //output is false! type=

this is not output empty, because the ascii char 2 is control char.

According to you say,So “unsigned char” is error!

unsigned char type=65;
cout<<"type="<<type<<endl;//type=A
LOG(INFO)<<"type="<<type; //output is false! type=65

yanchenyuvip avatar Apr 07 '21 05:04 yanchenyuvip

It use std::stringstream or std::wstringsteam to format, ref to this. you can test use this:

    std::stringstream ss;
    ss << static_cast<int>(type) << " vs " << type;
    std::cout << ss.str();

LOG(INFO)<<"type="<<type; //output is false! type=

this is not output empty, because the ascii char 2 is control char.

According to you say,So “unsigned char” is error!

unsigned char type=65;
cout<<"type="<<type<<endl;//type=A
LOG(INFO)<<"type="<<type; //output is false! type=65

have you define macro ELPP_UNICODE? if you define it, std::wstringstream is used.

    unsigned char type = 65;
    std::wstringstream ss;
    ss << type;
    std::wcout << "type=" << ss.str() << std::endl; //type=65

SnorlaxGengar avatar Apr 07 '21 06:04 SnorlaxGengar