// weather.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
//#include <iostream>
//#include <winsock.h>
//#include <string>
//#pragma comment(lib, "ws2_32.lib")
//using namespace std;
//int main(int argc, char* argv[])
//{
//struct hostent *pURL;
// struct sockaddr_in addr;
// WSADATA WSAData={0};
// SOCKET sockfd;
// string header;
// static char text[BUFSIZ];
//
// WSAStartup(MAKEWORD(2,2), &WSAData);
// sockfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
// pURL = gethostbyname("www.webxml.com.cn");
// addr.sin_family = AF_INET;
// addr.sin_addr.s_addr = *((unsigned long*)pURL->h_addr);
// addr.sin_port = htons(80);
// connect(sockfd,(SOCKADDR *)&addr,sizeof(addr));
// header="GET ";
// header.append("/WebServices/WeatherWebService.asmx/getWeatherbyCityName?theCityName=57073");
// header.append(" HTTP/1.1\r\n");
// header.append("HOST: ");
// header.append("www.webxml.com.cn");
// header.append("\r\nConnection: Close\r\n\r\n");
//
// send(sockfd, header.c_str(), strlen(header.c_str()), 0);
//
// while (recv(sockfd, text, BUFSIZ, 0) != NULL)
// {
// cout<<text;
// strnset(text, '\0', BUFSIZ);
// }
// closesocket(sockfd);
// WSACleanup();
// system("PAUSE");
//}
#include <stdio.h>
#include <windows.h>
#include <wininet.h>
#include <locale.h>
#pragma comment(lib,"Wininet.lib")
#include <vector>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <qstring.h>
#include <stdlib.h>//char转int
#include <read.h>//char转int
#include <cassert>
#include <qstring.h>
using namespace std;
int line_;
string result_;
CCom * cm;
//**写文件函数
void writeFile(char * char_)
{
int x=6;
FILE *fp=fopen("text.txt","w");
//fprintf(fp,"yes you are right !\ny=4+%d",x);
fprintf(fp,char_);
fclose(fp);
}
bool readxml()
{
int ii=0;
vector<char> v;
CHAR szUrl[] = "http://flash.weather.com.cn/wmaps/xml/china.xml";
// unsigned short *P="http://flash.weather.com.cn/wmaps/xml/china.xml";
CHAR szAgent[] = "";
HINTERNET hInternet1 =
InternetOpen(NULL,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,NULL);
if (NULL == hInternet1)
{
InternetCloseHandle(hInternet1);
return FALSE;
}
HINTERNET hInternet2 =
InternetOpenUrl(hInternet1,szUrl,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE,NULL);
///切换到“c/C++ ” Tab页 从下拉列表框中选择 “Preprocessor” ,去掉_MBCS,添加UNICODE,_UNICODE(注意逗号 把UNICODE去掉不报错了
if (NULL == hInternet2)
{
InternetCloseHandle(hInternet2);
InternetCloseHandle(hInternet1);
return FALSE;
}
DWORD dwMaxDataLength = 500;
PBYTE pBuf = (PBYTE)malloc(dwMaxDataLength*sizeof(TCHAR));
if (NULL == pBuf)
{
InternetCloseHandle(hInternet2);
InternetCloseHandle(hInternet1);
return FALSE;
}
DWORD dwReadDataLength = NULL;
BOOL bRet = TRUE;
do
{
ZeroMemory(pBuf,dwMaxDataLength*sizeof(TCHAR));
bRet = InternetReadFile(hInternet2,pBuf,dwMaxDataLength,&dwReadDataLength);
for (DWORD dw = 0;dw < dwReadDataLength;dw++)
{
v.push_back(pBuf[dw]);
}
} while (NULL != dwReadDataLength);
vector<char>::iterator i;
setlocale(LC_CTYPE,"chs");
wprintf(L"显示中文\n");
for(i=v.begin(); i!=v.end(); i++)
{ //wprintf(L"%c",*i);
printf("%c",*i);
ii=ii++;
Sleep(1);
}
Sleep(1000);
//下面是将vector<char> v 转换为char * 并写入txt
//vector是一个动态数组,如果定义为vector<char>,则是一个char数组
char *str = new char[v.size()+1];
copy(v.begin(),v.end(), str);
str[v.size()]=0;
cout<<str<<endl;
writeFile(str);
delete []str;
}
//***** 逐行读入txt
void readTxt(string file)
{
//setlocale( LC_ALL, ".936" );
ifstream infile;
infile.open(file.data()); //将文件流对象与文件连接起来
assert(infile.is_open()); //若失败,则输出错误消息,并终止程序运行
string s;
while(getline(infile,s))
{
// cout<<s<<endl;
line_=line_+1;
if (line_==14)
result_=s;
}
infile.close(); //关闭文件输入流
}
//逐个字符读入(包括空格与回车)
void readTxt1(string file)
{
ifstream infile;
infile.open(file.data()); //将文件流对象与文件连接起来
assert(infile.is_open()); //若失败,则输出错误消息,并终止程序运行
char c;
infile >> noskipws;
while (!infile.eof())
{
infile>>c;
cout<<c<<endl;
}
infile.close(); //关闭文件输入流
}
main(int argc, char* argv[])
{
int i=0;
while(1)
{
i=i++;
if (i==60)
{
readxml();
cm->readCommLinkLayer_Reg("","");
i=0;
}
Sleep(1000);
}
}
//
#include "stdafx.h"
//#include <iostream>
//#include <winsock.h>
//#include <string>
//#pragma comment(lib, "ws2_32.lib")
//using namespace std;
//int main(int argc, char* argv[])
//{
//struct hostent *pURL;
// struct sockaddr_in addr;
// WSADATA WSAData={0};
// SOCKET sockfd;
// string header;
// static char text[BUFSIZ];
//
// WSAStartup(MAKEWORD(2,2), &WSAData);
// sockfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
// pURL = gethostbyname("www.webxml.com.cn");
// addr.sin_family = AF_INET;
// addr.sin_addr.s_addr = *((unsigned long*)pURL->h_addr);
// addr.sin_port = htons(80);
// connect(sockfd,(SOCKADDR *)&addr,sizeof(addr));
// header="GET ";
// header.append("/WebServices/WeatherWebService.asmx/getWeatherbyCityName?theCityName=57073");
// header.append(" HTTP/1.1\r\n");
// header.append("HOST: ");
// header.append("www.webxml.com.cn");
// header.append("\r\nConnection: Close\r\n\r\n");
//
// send(sockfd, header.c_str(), strlen(header.c_str()), 0);
//
// while (recv(sockfd, text, BUFSIZ, 0) != NULL)
// {
// cout<<text;
// strnset(text, '\0', BUFSIZ);
// }
// closesocket(sockfd);
// WSACleanup();
// system("PAUSE");
//}
#include <stdio.h>
#include <windows.h>
#include <wininet.h>
#include <locale.h>
#pragma comment(lib,"Wininet.lib")
#include <vector>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <qstring.h>
#include <stdlib.h>//char转int
#include <read.h>//char转int
#include <cassert>
#include <qstring.h>
using namespace std;
int line_;
string result_;
CCom * cm;
//**写文件函数
void writeFile(char * char_)
{
int x=6;
FILE *fp=fopen("text.txt","w");
//fprintf(fp,"yes you are right !\ny=4+%d",x);
fprintf(fp,char_);
fclose(fp);
}
bool readxml()
{
int ii=0;
vector<char> v;
CHAR szUrl[] = "http://flash.weather.com.cn/wmaps/xml/china.xml";
// unsigned short *P="http://flash.weather.com.cn/wmaps/xml/china.xml";
CHAR szAgent[] = "";
HINTERNET hInternet1 =
InternetOpen(NULL,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,NULL);
if (NULL == hInternet1)
{
InternetCloseHandle(hInternet1);
return FALSE;
}
HINTERNET hInternet2 =
InternetOpenUrl(hInternet1,szUrl,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE,NULL);
///切换到“c/C++ ” Tab页 从下拉列表框中选择 “Preprocessor” ,去掉_MBCS,添加UNICODE,_UNICODE(注意逗号 把UNICODE去掉不报错了
if (NULL == hInternet2)
{
InternetCloseHandle(hInternet2);
InternetCloseHandle(hInternet1);
return FALSE;
}
DWORD dwMaxDataLength = 500;
PBYTE pBuf = (PBYTE)malloc(dwMaxDataLength*sizeof(TCHAR));
if (NULL == pBuf)
{
InternetCloseHandle(hInternet2);
InternetCloseHandle(hInternet1);
return FALSE;
}
DWORD dwReadDataLength = NULL;
BOOL bRet = TRUE;
do
{
ZeroMemory(pBuf,dwMaxDataLength*sizeof(TCHAR));
bRet = InternetReadFile(hInternet2,pBuf,dwMaxDataLength,&dwReadDataLength);
for (DWORD dw = 0;dw < dwReadDataLength;dw++)
{
v.push_back(pBuf[dw]);
}
} while (NULL != dwReadDataLength);
vector<char>::iterator i;
setlocale(LC_CTYPE,"chs");
wprintf(L"显示中文\n");
for(i=v.begin(); i!=v.end(); i++)
{ //wprintf(L"%c",*i);
printf("%c",*i);
ii=ii++;
Sleep(1);
}
Sleep(1000);
//下面是将vector<char> v 转换为char * 并写入txt
//vector是一个动态数组,如果定义为vector<char>,则是一个char数组
char *str = new char[v.size()+1];
copy(v.begin(),v.end(), str);
str[v.size()]=0;
cout<<str<<endl;
writeFile(str);
delete []str;
}
//***** 逐行读入txt
void readTxt(string file)
{
//setlocale( LC_ALL, ".936" );
ifstream infile;
infile.open(file.data()); //将文件流对象与文件连接起来
assert(infile.is_open()); //若失败,则输出错误消息,并终止程序运行
string s;
while(getline(infile,s))
{
// cout<<s<<endl;
line_=line_+1;
if (line_==14)
result_=s;
}
infile.close(); //关闭文件输入流
}
//逐个字符读入(包括空格与回车)
void readTxt1(string file)
{
ifstream infile;
infile.open(file.data()); //将文件流对象与文件连接起来
assert(infile.is_open()); //若失败,则输出错误消息,并终止程序运行
char c;
infile >> noskipws;
while (!infile.eof())
{
infile>>c;
cout<<c<<endl;
}
infile.close(); //关闭文件输入流
}
main(int argc, char* argv[])
{
int i=0;
while(1)
{
i=i++;
if (i==60)
{
readxml();
cm->readCommLinkLayer_Reg("","");
i=0;
}
Sleep(1000);
}
}