void CfileView::OnFileWrite()
{
// TODO: 在此添加命令处理程序代码
FILE *pFile =fopen("1.txt","w");
fwrite("http://unhappyless.008.net",1,strlen("http://unhappyless.008.net"),pFile);
   
fflush(pFile);    
}void CfileView::OnFileRead()
{
// TODO: 在此添加命令处理程序代码
FILE *pFile =fopen("1.txt","r");
TCHAR ch[100];
memset(ch,0,100*sizeof(TCHAR));
fread(ch,1,100,pFile);
MessageBox(ch);
}估计是下面的警告造成的...........正在编译...
file.cpp
fileDoc.cpp
fileView.cpp
c:\documents and settings\tcl\my documents\visual studio 2005\projects\文件操作\file\fileview.cpp(106) : warning C4996: “fopen”被声明为否决的
        d:\microsoft visual studio 8\vc\include\stdio.h(234) : 参见“fopen”的声明
        消息:“This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.”
c:\documents and settings\tcl\my documents\visual studio 2005\projects\文件操作\file\fileview.cpp(117) : warning C4996: “fopen”被声明为否决的
        d:\microsoft visual studio 8\vc\include\stdio.h(234) : 参见“fopen”的声明
        消息:“This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.”

解决方案 »

  1.   

    2005 默认使用Uncode,所以是乱码
      

  2.   

    用这个类进行文件的读写http://www.codeproject.com/file/stdiofileex.asp
      

  3.   

    VS2005没有用~~
    但是VC里面直接在菜单TOOLS-〉Option~
    然后选择Debug~~
    去掉Display Unicode String就可以了~~~
    你在编译器里面找找看~~~
      

  4.   

    FILE *pf =fopen("1.txt","wt");
      fprintf(pf, "http://unhappyless.008.net");
      fclose (pf);  ...
      FILE* pf = fopen ("1.txt", "rt");
      char buf[1024] = {0};
      fget (buf, sizeof(buf), pf);
      fclose (pf);
      MessageBox (...
      

  5.   

    这个不是unicode造成的,而是在VS2005里,对很多不安全的字符串及文件操作都增加了安全的函数,在函数名后面加上_s的,而对于老的函数就会报4996的警告
      

  6.   

    这么麻烦呀,还要用老外写的类.........那些显示乱码的问题在 vc6.0 下是没有的.有没有简单点的解决方法,而且还要在uncode下
      

  7.   

    TO: deanwong()  
     
       FILE *pf =fopen("1.txt","wt");
      fprintf(pf, "http://unhappyless.008.net");
      fclose (pf);  ...
      FILE* pf = fopen ("1.txt", "rt");
      char buf[1024] = {0};
      fget (buf, sizeof(buf), pf);
      fclose (pf);
      MessageBox (...
      
     
    ==================================================================error C3861: “fget”: 找不到标识符
      

  8.   

    FILE* pf;
    fopen_s(&pf, "1.txt", "r");
      

  9.   

    error C3861: “fget”: 找不到标识符SORRY, 写错了,是 fgets,少写了一个s
      

  10.   

    一开始看到警告我也那么改结果是运行时错误错误发生在  fread.c  的 101 行  ,表达式:( stream!=NULL)
      

  11.   

    deanwong() 的方法做如下细微修改后能解决问题 FILE* pf = fopen ("1.txt", "rt");
      TCHAR buf[1024] = {0};
      fgetws (buf, sizeof(buf), pf);
      fclose (pf);
     
    MessageBox(buf);
    但还有疑问,是不是fopen() 不能用了,与之对应的接受宽字符的函数是什么?
      

  12.   

    宽字符用 
      FILE *_wfopen( const wchar_t *filename, const wchar_t *mode ); 代替 fopen  int fwprintf( FILE *stream, const wchar_t *format [, argument ]...); 代替 fprintf
     
      fgetws 代替 fgets
     
      fclose 不变
      

  13.   

    那 fread() 和 fwrite() 呢?
      

  14.   

    fread 和 fwrite 直接写固定字节大小,和字符没有关系,照用不误,但如果你非要用这两个函数来写字符串就要自己计算字节大小了,同样一个字符串宽字符的字节要大一倍。