I want to verify BOM in UTF-8, and wrote the c++ codes below.
However, the result was 0XFFFFFFEF, 0XFFFFFFBB, 0XFFFFFFBF.
This is different from what I expected 0XEF, 0XBB, 0XBF.
Why did the result became above?
By the way, the UTF-8 file used was made by Notepad++.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char file[]="/*UTF-8 file*/";
char a[3]{};
ifstream ifs(file, ios_base::binary);
ifs.read(a, static_cast<streamsize>(sizeof(a)));
cout << showbase << uppercase;
for(int i:a){
cout << hex << i << endl;
}
}
Environment
GCC 9.2.0
compile option:-std=c++2a
for(int i:a){
over achar
array? Hmmmm... sign extension. - WhozCraig