void outputStuff( tostream& os )
{
// output stuff to the stream
os << ....
}
假如你传递的是tstringstream 对象将没有问题(例如,它流出宽字符),但是假如你传递的是tofstream 将得到怪异的结果(因为所有内容都被窄化了)。
//目标::建将文件小写字母,改成大写,写入另一个文件,//unicode文件
void main( )
{
FILE *f1;
FILE *f2;
//
setlocale(LC_ALL, ""); //重要,否则不能正常处理,出现乱码 setlocale(LC_ALL, "chs")也可以直接指定中国;
//locale loc ( "English" );
locale loc ( "Chinese" ); //or
wchar_t wc;
wchar_t wcstr[2]=L"好";
wstring sf1=L"C:\\Test.ini"; //该文件事先建好。
wstring sf2=L"C:\\Test.txt";
int fileOpen;
fileOpen=_wfopen_s(&f1,sf1.c_str(),L"rt+,ccs=UNICODE");
if (fileOpen!=0)// C4996 ///以读文本文件方式打开,字符指定为Unicode
// Note: _wfopen is deprecated; consider using _wfopen_s instead
{
wprintf(L"_wfopen failed!\n");
return ;
}
fileOpen=_wfopen_s(&f2,sf2.c_str(),L"wt+,ccs=UNICODE");
if (fileOpen!=0)// C4996 //write
// Note: _wfopen is deprecated; consider using _wfopen_s instead
{
wprintf(L"_wfopen failed!\n");
return ;
}
fpos_t pos; //文件位置
long ipos=0;
while(!feof(f1)) //判断的是否文件结束。
{
///read s char from f1 write to f2
fgetpos(f1 , &pos );//获取当前位置 ,用fsetpos(f1,&pos)定位。或fseek();
ipos=ftell(f1);
wc=getwc(f1);