I have a file which contains data stored as UTF-8 encoded using the Notepad application.
I am now attempting to read the data into a wide char buffer. But each time I seem to be reading some garbage information in the beginning of the read information.
I assume that these are BOM markers.
How can I eliminate these characters as I read the file contents into a wchar_t buffer ?
Code:
#include "stdafx.h"
#include<iostream>
#include<fstream>
#include <sstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
FILE *yyin;
wchar_t *buffer=(wchar_t *)malloc(sizeof(wchar_t)*100);
wchar_t *filepath=L"C:\\Encode\\1.txt";
_wfopen_s(&yyin,filepath,L"r");
fgetws(buffer,100,yyin);
wprintf(buffer);
wprintf(L"\n");
fclose(yyin);
return 0;
}
The information read into memory is as follows.
The file originally only contains the string "This is a file".