problem reading unicode file in C/C++

Dear all,

I need to read a unicode file using C or C++. I have tried several pieces of code, but none of those seems to work. The following code, for example, should read the first line of the file and write it to some output file, but it doesn't do that. The outputfile is still empty after I run the program.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
	FILE *in=fopen("F:\\InputFile","r");
	FILE *out=fopen("F:\\OutputFile","w");
	wchar_t mystring[100];
	fgetws (mystring , 100 , in);
	fwprintf(out, mystring);
	fclose (in);
	fclose (out);
	return 0;
}


Could someone please let me know why this doesn't work? I am new to C/C++ and by now in deep despair.

Thanks,
Anne
Neither C nor C++ know what "Unicode" means. They only understand files as a stream of bits. If you don't tell it how to interpret this "Unicode" file, no one will.
The GNU iconv library is often used
http://www.gnu.org/software/libiconv/

Good luck!
1
2
FILE *in=fopen("C:\\InputFile","rb");
FILE *out=fopen("C:\\OutputFile","wb");


You need to specify (b)inary
Last edited on
Topic archived. No new replies allowed.