麻烦高手看看 ~~~ Vc++6.0 建立的console applicaion 支持 MFC 的
这是网上一个简单的下载程序代码
编译的时候会出现错误
: error C2065: 'Download' : undeclared identifier
: error C2373: 'Download' : redefinition; different type modifiersError executing cl.exe.
#include "stdafx.h"
#include "001.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif#include<wininet.h>
#pragma comment(lib, "Wininet.lib")/////////////////////////////////////////////////////////////////////////////
// The one and only application objectCWinApp theApp;using namespace std;int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0; char url[1000];
while(cin>> url && strcmp(url,"quit")!=0)
{
try
{
cout <<"目标URL: "<< url << endl;
Download(url);
}
catch (char* e)
{
cout << e << endl <<endl;
}
} return nRetCode;}void Download(char url[])
{
char buffer[100000];
DWORD bytes_read;
HINTERNET internet=InternetOpen("HTTP Downloader",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,NULL);
if(!internet)
throw "InternetOpen error!";
HINTERNET file_handle=InternetOpenUrl(internet,url,NULL,0,INTERNET_FLAG_RELOAD,0);
if(!file_handle)
throw "InternetOpenUrl error! - Maybe you should add Http:// or Ftp://";
BOOL b=InternetReadFile(file_handle,buffer,100000,&bytes_read);
if(!b)
throw"InternetReadFile error!"; buffer[bytes_read] = 0; cout<< buffer << endl << endl; InternetCloseHandle(internet);
};
麻烦高手改正下代码 谢谢
这是网上一个简单的下载程序代码
编译的时候会出现错误
: error C2065: 'Download' : undeclared identifier
: error C2373: 'Download' : redefinition; different type modifiersError executing cl.exe.
#include "stdafx.h"
#include "001.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif#include<wininet.h>
#pragma comment(lib, "Wininet.lib")/////////////////////////////////////////////////////////////////////////////
// The one and only application objectCWinApp theApp;using namespace std;int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0; char url[1000];
while(cin>> url && strcmp(url,"quit")!=0)
{
try
{
cout <<"目标URL: "<< url << endl;
Download(url);
}
catch (char* e)
{
cout << e << endl <<endl;
}
} return nRetCode;}void Download(char url[])
{
char buffer[100000];
DWORD bytes_read;
HINTERNET internet=InternetOpen("HTTP Downloader",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,NULL);
if(!internet)
throw "InternetOpen error!";
HINTERNET file_handle=InternetOpenUrl(internet,url,NULL,0,INTERNET_FLAG_RELOAD,0);
if(!file_handle)
throw "InternetOpenUrl error! - Maybe you should add Http:// or Ftp://";
BOOL b=InternetReadFile(file_handle,buffer,100000,&bytes_read);
if(!b)
throw"InternetReadFile error!"; buffer[bytes_read] = 0; cout<< buffer << endl << endl; InternetCloseHandle(internet);
};
麻烦高手改正下代码 谢谢
如cnzdgs所说的,可以把这个声明放在.h文件里面。当然,也可以放在_tmain前面。
另外如果这个函数单单只是在本cpp程序里面用,也就是对本cpp来说是私有的,那建议用后者,并在函数声明的时候加上static.