使用CFile前要做些什么工作?为何我的程序总是遇到以下错误:
// Translator.cpp : Defines the entry point for the console application.
//#include "stdafx.h" 
#include <iostream>
CFile SourceFile;int main(int argc, char* argv[])
{ int a;
return 0;
if(!SourceFile.Open("e:\readme.txt",ios::in))
SourceFile.Close();
}
--------------------Configuration: Translator - Win32 Debug--------------------
Compiling...
Translator.cpp
F:\Mywork\myc++\Translator\Translator.cpp(6) : error C2146: syntax error : missing ';' before identifier 'SourceFile'
F:\Mywork\myc++\Translator\Translator.cpp(6) : error C2501: 'CFile' : missing storage-class or type specifiers
F:\Mywork\myc++\Translator\Translator.cpp(6) : fatal error C1004: unexpected end of file found
Error executing cl.exe.Translator.exe - 3 error(s), 0 warning(s)

解决方案 »

  1.   

    你的好象是不对都这么用
    CFile SourceFile;
    if(!SourceFile.Open("E:\\readme.txt"/*你此处一定错误*/,CFile::modemRead | CFile::modemWrite))
    AfxMessageBox("Open File error");
    SourceFile.Close();
      

  2.   

    创建console application时,选择有MFC支持的那种。
      

  3.   

    看不懂它是什么!你是在做基于MFC的程序里用 CFile呢!还是就在由几个cpp和hpp文件组成的小工程里,使用像C语言的文件打开函数?是哪个?(看的像后一个)
      

  4.   

    回 kingofvc(其实恶狼2000也不错)
    namespace std是默认的,加不加都没影响。回 Pipi0714(皮皮0714) 
    编译器不是说我open错了,而是CFile SourceFile;错了。回papaya_stone(^_^)shentong(^_^) 
    bingo, thanks 
    回 zhdleo(叮东) 
    本来想着包含个头文件就行了,怎知不合规格,还是重新建个console application with MFC surport解决问题。thank you all.