Thanks.
This is the .txt file I open:
Package Requires Reboot = no
New Uninstall Key = inf2
Progress Thread Wait = Success
[Finish]
[ResponseResult]
ResultCode = 0
It is read into wbuf I verified it. I also tried to attach it but the site says its an invalid file.
Code:
#include <Windows.h>
#include <locale>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
#include <iostream> // std::cout
using namespace std;
int main()
{
string szFilename = "IntelChipset.log";
std::wifstream ifs(szFilename.c_str(), std::ifstream::binary);
if(ifs)
{
// get length of file:
ifs.seekg(0, ifs.end);
std::streampos length = ifs.tellg();
ifs.seekg(0, ifs.beg);
wchar_t * wbuf = new wchar_t [length];
cout << " Reading " << length << " characters... \n";
// read data as a block:
ifs.read(wbuf,length);
wstring wstr;
wstr.copy(wbuf,length,0);
wcout << " wstr " << wstr << '\n';
for(int i=0; i<length; i++) cout << (char)wstr[i];
std::string::size_type pos = 0;
if((pos = wstr.find(L"R e b o o t", pos)) != std::string::npos)
{
cout << "Found at "<< pos << '\n';
}
else
{
cout << " Not found " << '\n';
}
char * buf = new char[length];
UINT CodePage = CP_UTF8;
int buffer_size_needed = WideCharToMultiByte(
CodePage,
WC_ERR_INVALID_CHARS,
wbuf, //string_to_convert,
-1,
NULL,
0,
NULL,
NULL);
cout << " buffer_size_needed " << buffer_size_needed << '\n';
//int ret = wcstombs(buf, wbuf, length);
int ret = WideCharToMultiByte(
CodePage,
0,
wbuf,
-1,
buf,
buffer_size_needed,
NULL,
NULL);
cout << " ret " << ret << '\n';
string s(buf);
cout << " \n string " << s << '\n';
}
else
{
cout << " Error opening " << szFilename << "\n";
return 1;
}
ifs.close();
return 0;
}