Ok i finally figured out , the problem was due to little endianess , which screwed the file. and since i was getting osme output i never thought to look at it. the solution was just to replace the file reading method by:
in.imbue(std::locale(fin.getloc(), new std::codecvt_utf16<wchar_t, 0x10ffff,
std::codecvt_mode(std::little_endian|std::consume_header)>);
after fixing this the rest of the code worked as expected.
Thanks @Richard , @nv3 ,@pablo for response. much appreciated.