#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <locale>
#include <iostream>
int main(int argc, char* argv[])
{
if (argc>1)
{
char* full_path= argv[1];
FILE * fp ;
char * test = setlocale(LC_ALL,"chs");
char tmpbuff[1024];
fp = fopen(full_path,"r, ccs=UTF-8"); // linux does not support ccs=UTF-8
size_t result = fread(tmpbuff, 1, sizeof(tmpbuff)-1,fp);
if (result >0)
{
tmpbuff[result] = 0;
printf("result is %d.\n", result);
}
wchar_t* mbyte_buf=new wchar_t[result*4];
char* start_pos = tmpbuff;
if(start_pos[0]==(char)0xEF && start_pos[1]==(char)0xBB && start_pos[2]==(char)0xBF) //0xEF,0xBB,0xBF
{
start_pos += 3;
result -= 3;
std::cout<< "There is UTF-8 BOM in " << full_path << std::endl;
}
else
{
std::cout<< "There is no UTF-8 BOM in " << full_path << std::endl;
}
int n = ::MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)start_pos, result, mbyte_buf, result/*, NULL, NULL*/);
std::wcout<<mbyte_buf<<std::endl;
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <locale>
#include <iostream>
int main(int argc, char* argv[])
{
if (argc>1)
{
char* full_path= argv[1];
FILE * fp ;
char * test = setlocale(LC_ALL,"chs");
char tmpbuff[1024];
fp = fopen(full_path,"r, ccs=UTF-8"); // linux does not support ccs=UTF-8
size_t result = fread(tmpbuff, 1, sizeof(tmpbuff)-1,fp);
if (result >0)
{
tmpbuff[result] = 0;
printf("result is %d.\n", result);
}
wchar_t* mbyte_buf=new wchar_t[result*4];
char* start_pos = tmpbuff;
if(start_pos[0]==(char)0xEF && start_pos[1]==(char)0xBB && start_pos[2]==(char)0xBF) //0xEF,0xBB,0xBF
{
start_pos += 3;
result -= 3;
std::cout<< "There is UTF-8 BOM in " << full_path << std::endl;
}
else
{
std::cout<< "There is no UTF-8 BOM in " << full_path << std::endl;
}
int n = ::MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)start_pos, result, mbyte_buf, result/*, NULL, NULL*/);
std::wcout<<mbyte_buf<<std::endl;
}
return 0;
}