C
Christopher
I loaded a file using these two blocks of code and examined the
results. I did not see what I expected. Each wchar_t seems to have its
byte order swapped when looking at the results as bytes. When
examining the contents of the wstring, extra '0' characters are
inserted before each expected character.
My colleague claims that its some microsoft/intel thing. That doesn't
help me to write code that handles it though.
Can someone explain?
//---
// Load the file as wide character text
{
// Load the Init Document
std::wifstream initDocFile(initDocumentPath.c_str());
ASSERT_TRUE( initDocFile );
// Copy the contents of the file into a string
std::wstring initDoc((std::istreambuf_iterator<wchar_t,
std::char_traits<wchar_t> >(initDocFile)),
(std::istreambuf_iterator<wchar_t,
std::char_traits<wchar_t> >()));
ASSERT_FALSE( initDoc.empty() );
// Close the file
initDocFile.close();
}
//-----
Hovering over initDoc in Visual Studio 2008 shows:
<
0
A
0
T
0
etc, etc
//---
// Load the file as bytes
{
// Load the Init Document
std::ifstream initDocFile(initDocumentPath.c_str(),
std::fstream::binary);
ASSERT_TRUE( initDocFile );
// Get the size of the file
initDocFile.seekg(0,std::ios::end);
std::streampos numBytes = initDocFile.tellg();
initDocFile.seekg(0,std::ios::beg);
// Copy the contents of the file into a vector
std::vector<char> initDoc(numBytes);
initDocFile.read(&initDoc[0], numBytes);
ASSERT_FALSE( initDoc.empty() );
// Close the file
initDocFile.close();
}
//-----
Hovering over initDoc in Visual Studio 2008 shows:
60
0
65
0
etc.
etc.
//----
Looking at the file in a hex editor shows:
3C 00 41 00 54 00 etc. etc.
Furthermore,
1) I cannot double click the file and open it as XML on Windows Server
2003. It says "Invalid character. Error processing resource"
2) I cannot hover over initDoc in Visual Studio 2008, click the down
arrow, and open the variable in the text visualizer, it shows "<"
3) I cannot hover over initDoc in Visual Studio 2008, click the down
arrow, and open the variable in the xml visualizer, it shows "A
declaration was not closed. Error processing resource"
Someone help me to understand.
results. I did not see what I expected. Each wchar_t seems to have its
byte order swapped when looking at the results as bytes. When
examining the contents of the wstring, extra '0' characters are
inserted before each expected character.
My colleague claims that its some microsoft/intel thing. That doesn't
help me to write code that handles it though.
Can someone explain?
//---
// Load the file as wide character text
{
// Load the Init Document
std::wifstream initDocFile(initDocumentPath.c_str());
ASSERT_TRUE( initDocFile );
// Copy the contents of the file into a string
std::wstring initDoc((std::istreambuf_iterator<wchar_t,
std::char_traits<wchar_t> >(initDocFile)),
(std::istreambuf_iterator<wchar_t,
std::char_traits<wchar_t> >()));
ASSERT_FALSE( initDoc.empty() );
// Close the file
initDocFile.close();
}
//-----
Hovering over initDoc in Visual Studio 2008 shows:
<
0
A
0
T
0
etc, etc
//---
// Load the file as bytes
{
// Load the Init Document
std::ifstream initDocFile(initDocumentPath.c_str(),
std::fstream::binary);
ASSERT_TRUE( initDocFile );
// Get the size of the file
initDocFile.seekg(0,std::ios::end);
std::streampos numBytes = initDocFile.tellg();
initDocFile.seekg(0,std::ios::beg);
// Copy the contents of the file into a vector
std::vector<char> initDoc(numBytes);
initDocFile.read(&initDoc[0], numBytes);
ASSERT_FALSE( initDoc.empty() );
// Close the file
initDocFile.close();
}
//-----
Hovering over initDoc in Visual Studio 2008 shows:
60
0
65
0
etc.
etc.
//----
Looking at the file in a hex editor shows:
3C 00 41 00 54 00 etc. etc.
Furthermore,
1) I cannot double click the file and open it as XML on Windows Server
2003. It says "Invalid character. Error processing resource"
2) I cannot hover over initDoc in Visual Studio 2008, click the down
arrow, and open the variable in the text visualizer, it shows "<"
3) I cannot hover over initDoc in Visual Studio 2008, click the down
arrow, and open the variable in the xml visualizer, it shows "A
declaration was not closed. Error processing resource"
Someone help me to understand.