printf
출력을 std::string
변수 로 변환하려고 합니다. 다음 for 루프가 있습니다.
for(i=0; i<53; i++) {
printf("%02X", pbRecvBuffer[i]);
}
이 루프의 출력은 다음과 같은 16 진수 값 01445420434F2..
입니다.. 내 첫 번째 시도는 stringstream
다음과 같이 사용 되었습니다.
stringstream os;
for(i=0; i<53; i++)
os << std::hex << pbRecvBuffer[i];
std::cout << os << std::endl;
불행히도 이것은 잘못된 결과를 얻었습니다. 누군가가 직접보고 나를 도울 수있을 것입니다.
일반적으로 예를 들어 16 진수 및 int 형식의 스트림을 사용하는 것은 다음을 수행하는 것이 좋습니다.
std::ios_base::fmtflags f(out.flags()); // Init
out <<std::hex << std::setfill('0') << std::setw(2) << (unsigned int)pbRecvBuffer[i];
out.flags(f); // restore
일반적으로 out은 std :: cout, std :: ostringstream, std :: basic_ostream 등에서 파생 된 객체입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다