In the daily development we often use the market data, a lot of times we are based on a benchmark data area to construct the market, but with the passage of time to construct the data and real market data gap between more and more big.
This question takes AG1309 as an example to explain how to use C + + program to obtain the Sina market data. (If the data obtained from the contract expires will not be available, change the contract information at this time).
OK, here will no longer nonsense, directly give the source code for everyone to learn!
HttpDataTest.cpp: Defines the entry point for a console application.
#include "stdafx.h" #include #include #include #include #include the #include #define MAXSIZE 1024 #pragma comment (lib, "Wi
Ninet.lib ") void Urlopen (_tchar*);
std::string getsubbtfind (char* lpsz);
int Token (const char* PSEP, char* pstr, std::vector& Refvec);
int _tmain (int argc, _tchar* argv[]) {Urlopen (_t ("http://hq.sinajs.cn/list=AG1309"));
System ("pause");
return 0; } void Urlopen (_tchar* url) {hinternet hsession = InternetOpen (_t ("Urltest"), internet_open_type_preconfig, NULL, NULL
, 0);
if (hsession!= null) {hinternet hhttp = InternetOpenUrl (hsession, URL, null, 0, Internet_flag_dont_cache, 0);
if (hhttp!= NULL) {wprintf_s (_t ("%s\n"), URL);
Char Temp[maxsize];
ULONG number = 1;
while (number > 0) {internetreadfile (hhttp, Temp, MAXSIZE-1, &number);
Temp[number] = ' the ';
std::string str= Getsubbtfind (Temp);
;
Char szpstr[1024];
strcpy (Szpstr, Str.c_str ());
Std::vector Vec;
Token (",", Szpstr, VEC);printf ("%s\n", Temp);
for (int i=0; I {printf ("%s\n", Vec[i]);
} internetclosehandle (Hhttp);
Hhttp = NULL;
} internetclosehandle (Hsession);
Hsession = NULL;
} std::string Getsubbtfind (char* lpsz) {std::string scrstr=lpsz;
std::string str_temp= "";
int Len=strlen (LPSZ);
int Beginpos=scrstr.find ("\");
Scrstr=scrstr.substr (Beginpos+1,len);
int Endpos=scrstr.find ("\");
Str_temp=scrstr.substr (0,endpos);
return str_temp; int Token (const char* PSEP, char* pstr, std::vector& Refvec) {for (char* outer = strtok (pstr, PSEP); NULL!= outer;
Outer = strtok (NULL, PSep)) {refvec.push_back (outer);
return 0;
}
The above code runs under VS2008 results as follows:
The above is the entire content of this article, I hope to be proficient in the application of C + + program to grab data to help