By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,275 Members | 2,076 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,275 IT Pros & Developers. It's quick & easy.

C++11 , How to get the entire NYSE listing daily?

P: 69
In C++11.

On a Windows computer.

How do I add to my program a way for it to download from the internet the entire NYSE listing daily?

I am still learning C++11.

If you give an example that is stable, and it is really simple, then I can go from there.

Code that is baby level simple please.

4 Weeks Ago #1
Share this Question
Share on Google+
5 Replies

P: 94
This program to get the source by specifying the URL and save it in a binary file.(Only Windows)
Expand|Select|Wrap|Line Numbers
  1. #include "pch.h"
  2. #include <iostream>
  4. #include <windows.h>
  5. #include <stdio.h>
  6. #include <wininet.h>
  7. #include <tchar.h>
  8. #include <locale.h>
  10. #pragma comment(lib,"wininet.lib")
  12. //      Get data from the specified URL and save it in a file in binary
  13. int webBinGet(HINTERNET hInet, TCHAR* url, FILE* fp);
  15. int _tmain(int argc, TCHAR** argv) {
  16.     HINTERNET hInet;
  17.     FILE* fp;
  19.     //      Sets the locale to display UNICODE characters correctly on stderr
  20.     _tsetlocale(LC_ALL, _TEXT(""));
  22.     if (argc != 3) {
  23.         _ftprintf(stderr, _TEXT("Usage : This_Prog_Name.exe [url] [save file name]\n"));
  24.         return 1;
  25.     }
  26.     //Start Internet connect(WinInet)
  27.     hInet = InternetOpen(TEXT("wxz123"),
  29.         NULL, NULL, 0);
  30.     if (hInet == NULL) {
  31.         _ftprintf(stderr, _TEXT("Failure the handl eacquisition\n"));
  32.         return 2;
  33.     }
  34.     if (_tfopen_s(&fp, argv[2], TEXT("wb"))) {
  35.         InternetCloseHandle(hInet);
  36.         _ftprintf(stderr, _TEXT("File Open Error %s\n"), argv[2]);
  37.         return 3;
  38.     }
  39.     if (webBinGet(hInet, argv[1], fp) < 0)
  40.         _ftprintf(stderr, _TEXT("Could not load source from internet successfully\n"));
  41.     InternetCloseHandle(hInet);
  42.     fclose(fp);
  43.     return 0;
  44. }
  46. //      Get HTML source from the URL and save binary file.
  48. int webBinGet(HINTERNET hInet, TCHAR* url, FILE* fp) {
  49.     char buf[1024];
  50.     HINTERNET hUrl;
  51.     //HTTP session Start,and URL open.
  52.     hUrl = InternetOpenUrl(hInet, url, NULL, 0, 0, 0);
  53.     if (hUrl == NULL) {
  54.         _ftprintf(stderr, _TEXT("URL Open Error %s\n"), url);
  55.         return -1;
  56.     }
  57.     //Read to the end
  58.     int len;
  59.     int size = 0;
  60.     for (;;) {
  61.         InternetReadFile(hUrl, buf, sizeof(buf), (LPDWORD)&len);
  62.         if (len <= 0)
  63.             break;
  64.         fwrite(buf, sizeof(buf[0]), len, fp);
  65.         size += len;
  66.     }
  67.     InternetCloseHandle(hUrl);
  68.     return len;     //      Return File size.
  69. }
After that, create a part to find your required tag and get the value in bin file.

If you run at a fixed time every day,
Use time scheduling(Wiindows).
4 Weeks Ago #2

P: 69
SioSio YES !

Thank you.

And it uses Unicode ! Yes again! Again Thank You. I wanted this program to be usable by any Unicode user. I have been starting with #define _UNICODE and #define UNICODE.

Direct, to the point, a bit of a stretch to keep up with it, but it looks like code that I can study and learn from.


I see that you use #include "pch.h". I have read about this and it seems to be used in some examples with Visual Studio. Does that mean that I have to use VS to use this code.

I am using CODE::BLOCKS 17.12 and GNU GCC Compiler.

My main is int WINAPI WinMain(...). I am compiling to a Windows GUI. I hope that if I study your code example that I can use it. It looks nice.

And, with #include "pch.h", does that mean that, in my final compiled program, that my headers will be compiled separately? I wanted the entire program to be one single executable with no dlls, etc. I have been using #define IDC_STATIC (-1). Or, does #include "pch.h" just make the compilation faster. Can I use this code without #include "pch.h"?

Really, Thanks SioSio.
4 Weeks Ago #3

P: 69
I am looking up your code (parts) and studying it and it seems to be written for Visual Studio. I am not getting the following to work:

Expand|Select|Wrap|Line Numbers
  1.     if (_tfopen_s(&fp, argv[2], TEXT("wb"))) {
  2.         InternetCloseHandle(hInet);
  3.         _ftprintf(stderr, _TEXT("File Open Error %s\n"), argv[2]);
  4.         return 3;
I looked up _tfopen_s and it does not seem to work outside of Visual Studio. I am trying to find how to do the VS parts in C or C++ by itself without VS.

4 Weeks Ago #4

P: 94
Yes, this source was written in VS.

#include "pch.h" is not required if the environment is not VS.

In Visual Studio, fopen cannot be used as it is (it is necessary to write #pragma warning (disable: 4996) at the beginning of the source), so use _fopen_s.
Expand|Select|Wrap|Line Numbers
  1. _tfopen_s(&fp、argv [2]、TEXT( "wb"))
  3. fp = fopen(argv[2], "wb");
4 Weeks Ago #5

P: 69
Thank you SioSio.

Last summer 2019 I decided to learn C++11.

I have no interest in using Visual Studio (at this time).

As a new C++ programmer, it has taken me sometimes hours to convert VS stuff to C++ code. Now I have been trying to stay away from VS studio stuff.

Your offer to help me with VS code was nice. I appreciate the offer. Thank you. But, I am looking for C++11 code.

At your level of expertise, maybe you can supply that code in C++? I can use any version of C++ up to 11 and I can use straight C. Would you please help me with doing this in C++ (up to C++11)?

Thank you SioSio.
3 Weeks Ago #6

Post your reply

Sign in to post your reply or Sign up for a free account.