资源简介
天气预报c++源码,有打包好的文件可使用,适合新手学习
代码片段和文件信息
// 123.cpp : 定义控制台应用程序的入口点。
//
#include “stdafx.h“
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
#include
#include
#include
#pragma comment(lib “ws2_32.lib“)
using namespace std;
string allHtml;
SOCKET sock;
char host[200];
char othPath[300];
char buf[1024];
void SendRequst(char *host char *othPath)
{
WSADATA wd;
WSAStartup(MAKEWORD(2 2) &wd);
sock = socket(AF_INET SOCK_STREAM 0);
sockaddr_in sa = { AF_INET };
int n = bind(sock (sockaddr*)&sa sizeof(sa));
struct hostent *p = gethostbyname(host);
sa.sin_port = htons(80);
memcpy(&sa.sin_addr p->h_addr 4);
n = connect(sock (sockaddr*)&sa sizeof(sa));
string reqInfo = “GET “ + (string)othPath + “ HTTP/1.1\r\nHost: “ + (string)host + “\r\nConnection:Close\r\n\r\n“;
send(sock reqInfo.c_str() reqInfo.size() 0);
}
char* U2G(const char* utf8) ///格式转换UTF-8 to GB2312
{
int len = MultiByteToWideChar(CP_UTF8 0 utf8 -1 NULL 0);
wchar_t* wstr = new wchar_t[len + 1];
memset(wstr 0 len + 1);
MultiByteToWideChar(CP_UTF8 0 utf8 -1 wstr len);
len = WideCharToMultiByte(CP_ACP 0 wstr -1 NULL 0 NULL NULL);
char* str = new char[len + 1];
memset(str 0 len + 1);
WideCharToMultiByte(CP_ACP 0 wstr -1 str len NULL NULL);
if (wstr) delete[] wstr;
return str;
}
int main()
{
int n;
strcpy_s(host “api.thinkpage.cn“);
strcpy_s(othPath “/v3/weather/daily.json?key=jfpj8mxwlz50yoix&location=beijing&language=zh-Hans&unit=c&start=0&days=5“);
SendRequst(host othPath);
while ((n = recv(sock buf sizeof(buf)-1 0)) > 0)
{
buf[n] = 0;
allHtml += buf;
}
closesocket(sock);
char *aa = U2G(allHtml.data());
cout << aa << endl; //输出整个网页
system(“pause“);
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-05-23 18:46 天气预报\
目录 0 2016-06-14 19:30 天气预报\666\
目录 0 2016-06-14 19:30 天气预报\666\666\
文件 34537472 2016-12-08 17:09 天气预报\666\666.sdf
文件 955 2016-06-14 19:30 天气预报\666\666.sln
文件 32768 2016-12-08 17:08 天气预报\666\666.v12.suo
文件 1888 2016-06-14 19:33 天气预报\666\666\666.cpp
文件 4643 2016-10-24 12:37 天气预报\666\666\666.vcxproj
文件 1574 2016-10-24 12:37 天气预报\666\666\666.vcxproj.filters
目录 0 2016-06-14 19:31 天气预报\666\666\Debug\
文件 359 2016-12-08 16:16 天气预报\666\666\Debug\666.log
文件 222861 2016-06-14 19:33 天气预报\666\666\Debug\666.obj
文件 2949120 2016-10-24 12:37 天气预报\666\666\Debug\666.pch
目录 0 2016-06-14 19:31 天气预报\666\666\Debug\666.tlog\
文件 153 2016-12-08 16:16 天气预报\666\666\Debug\666.tlog\666.lastbuildstate
文件 4110 2016-12-08 16:14 天气预报\666\666\Debug\666.tlog\cl.command.1.tlog
文件 25656 2016-12-08 16:16 天气预报\666\666\Debug\666.tlog\CL.read.1.tlog
文件 572 2016-12-08 16:16 天气预报\666\666\Debug\666.tlog\CL.write.1.tlog
文件 3056 2016-12-08 16:15 天气预报\666\666\Debug\666.tlog\li
文件 2762 2016-12-08 16:16 天气预报\666\666\Debug\666.tlog\li
文件 296 2016-12-08 16:16 天气预报\666\666\Debug\666.tlog\li
文件 283725 2016-12-08 16:14 天气预报\666\666\Debug\main.obj
文件 10434 2016-10-24 12:37 天气预报\666\666\Debug\stdafx.obj
文件 1707008 2016-12-08 16:14 天气预报\666\666\Debug\vc120.idb
文件 618496 2016-12-08 16:14 天气预报\666\666\Debug\vc120.pdb
文件 5685 2016-12-08 16:12 天气预报\666\666\jiemian.h
文件 604 2016-06-21 10:49 天气预报\666\666\kmp.h
文件 5751 2016-12-08 16:13 天气预报\666\666\main.cpp
文件 1482 2016-06-14 19:30 天气预报\666\666\ReadMe.txt
文件 209 2016-06-14 19:30 天气预报\666\666\stdafx.cpp
文件 234 2016-06-14 19:30 天气预报\666\666\stdafx.h
............此处省略143个文件信息
评论
共有 条评论