How to obtain SINA market data using C + + program _c language

Source: Internet
Author: User
Tags strtok

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.