wangzewu 发表于 2010-11-3 20:28:37

open file

我想打开d:\try\wzw.txt(txt里是一个字符串I love flowers)把这个字符串读出来显示到屏幕上;
这是dos下的
main()
{
FILE *fp;
if((fp=fopen("d:\\try\wzw.txt","r"))==NULL)
{
printf("文件不存在\n");exut(0);
};
while(!feof(fp));
putchar(fgetc(fp));
fclose(fp);
printf("\n");
}
VC2008这样改过不了,不知道为什么.#include <iostream>

int main()
{
FILE *fp;
if((fp=fopen("d:\\try\wzw.txt","r"))==NULL)
{
printf("文件不存在\n");exut(0);
};
while(!feof(fp));
putchar(fgetc(fp));
fclose(fp);
printf("\n");
return 0;
}
c:\documents and settings\zewu\my documents\visual studio 2008\projects\dos\dos\dos.cpp(6) : warning C4129: “ ”: 不可识别的字符转义序列
c:\documents and settings\zewu\my documents\visual studio 2008\projects\dos\dos\dos.cpp(6) : warning C4129: “w”: 不可识别的字符转义序列
c:\documents and settings\zewu\my documents\visual studio 2008\projects\dos\dos\dos.cpp(6) : warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
      d:\microsoft visual studio 9.0\vc\include\stdio.h(237) : 参见“fopen”的声明
c:\documents and settings\zewu\my documents\visual studio 2008\projects\dos\dos\dos.cpp(8) : error C3861: “exut”: 找不到标识符

潇潇 发表于 2010-11-4 11:14:59

#include <stdio.h>
#include <stdlib.h>

int main()
{
        FILE *fp;
        char * _MyFileName;
        _MyFileName ="d:\\新建 文本文档.txt";
        fp = fopen(_MyFileName,"r");
        if(fp==NULL)
        {
                printf("文件不存在\n");
        }
        else
        {
                while(!feof(fp))
                {
                        putchar(fgetc(fp));
                        //printf("\n");
                }
                fclose(fp);
        }
        system("pause"); //暂停控制台,防止一闪而过
        return 0;
}参考下吧……

wangzewu 发表于 2010-11-4 12:07:12

谢谢 老大.我就去开vc2008.
页: [1]
查看完整版本: open file