使用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)
// 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)
CFile SourceFile;
if(!SourceFile.Open("E:\\readme.txt"/*你此处一定错误*/,CFile::modemRead | CFile::modemWrite))
AfxMessageBox("Open File error");
SourceFile.Close();
namespace std是默认的,加不加都没影响。回 Pipi0714(皮皮0714)
编译器不是说我open错了,而是CFile SourceFile;错了。回papaya_stone(^_^)shentong(^_^)
bingo, thanks
回 zhdleo(叮东)
本来想着包含个头文件就行了,怎知不合规格,还是重新建个console application with MFC surport解决问题。thank you all.