I have three programs. the code of programA is shown below:
#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <locale>
using namespace std;
int _tmain( void )
{
wstringstream s2;
TCHAR waTemp2[4] = {0xA0, 0xA1, 0x00A2, 0xA3};
for (int i = 0; i < 4; i++)
{
s2<< hex <<(unsigned int)waTemp2[i] << " ";
}
wstring strData2 = s2.str();
wcout << strData2.c_str() <<endl;
return 0;
}
here is the output:
a0 a1 a2 a3
the code of programB is shown below:
#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <locale>
using namespace std;
int _tmain( void )
{
wstringstream s2;
TCHAR waTemp2[4] = {0xA0, 0xA1, 0x00A2, 0xA3};
for (int i = 0; i < 4; i++)
{
s2<< hex << waTemp2[i] << " ";
}
wstring strData2 = s2.str();
wcout << strData2.c_str() <<endl;
return 0;
}
here is the output:
????
the code of the programC is shown below:
#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <locale>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
wstringstream s2;
TCHAR waTemp2[4] = {0xA0, 0xA1, 0x00A2, 0xA3};
for (int i = 0; i < 4; i++)
{
s2 << std::wios::hex <<(unsigned int)waTemp2[i] << " ";
}
wstring strData2 = s2.str();
wcout<< strData2.c_str() <<endl;
return 0;
}
here is the output:
2048160 2048161 2048162 2048163
could you tell me the reasons the difference between std::wios::hex and std::hex, std::hex << waTemp2[i] and std::hex << (unsigned int)waTemp2[i] resulted in different of the output.
thank you very much!