• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3064
  • Last Modified:

Use C++ to read in url data

Hello

I am trying to write a C++ program that could read in quote info from yahoo "http://finance.yahoo.com/d/quotes.csv?s=YH&f=sl1d1t1c1ohgv&e=.csv"

I know this can be done easily with php and other scripting language.  Is there a way to do it so that I can get the data and be able to display in in my C++ application directly?

Thanks,
0
cdloves
Asked:
cdloves
  • 4
  • 4
  • 3
2 Solutions
 
gckcmcCommented:
sure....it is a standard CSV format...basically you just parse the input stream breaking on commas.  you can store the data however you want...gimme a minute and I'll show you some code.
0
 
gckcmcCommented:
btw, do you have any system level dependencies, like unix vs windows?  
0
 
cdlovesAuthor Commented:
window
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
gckcmcCommented:
well, first thing you could do is go grab the sample dll library code from the 3W, which provides you http access to windows environment.  http://www.w3.org/Library/User/Platform/WinDLL.html#io

I'm assuming you actually want to do this streaming, which is what you would need the above code to get you the 'get's...if you are actually saving the csv files to a disk and just want to parse them in your c++ file, you can skip this step, and just go to a while not EOF loop, doing char parsing with commas as the delimiter test.
0
 
mrwad99Commented:
>>  Is there a way to do it so that I can get the data and be able to display in in my C++ application directly?

I would do it the easy way
      URLDownloadToFile(NULL,"http://finance.yahoo.com/d/quotes.csv?s=YH&f=sl1d1t1c1ohgv&e=.csv","c:\\MyCSV.csv",0,NULL);      

ifstream input("c:\\MyCSV.csv");
char oneLine[512];

while (input.good()) {
      input.getline(oneLine, 512);
      // Do whatever with one line of the CSV file....
}

0
 
cdlovesAuthor Commented:
cg,
The sample dll file you mentioned is windll, I assume?  If so how do I include it in the project and how to use it? The link doesn't help much in that regard.

mrwad,
I included urlmon.h file in my project and used your sample code but the compiler complained that it couldn't resolve UrlDownLoadToFile. I already have SDK installed.
0
 
mrwad99Commented:
Yeah, you need to link with Urlmon.lib.  Add that in project->settings->Link->project options if you are using VC++.  
0
 
gckcmcCommented:
yes it is a windll file.  it is in the project settings, assuming your using msvc, you include it in the settings there.  mrwad99's solution will work if you want to use temp files....if not, then you need to stream it.
0
 
mrwad99Commented:
cdloves:

Did you link with that DLL ?
0
 
cdlovesAuthor Commented:
Yes, I got it to work mrwad.  Thanks both for helping.
0
 
mrwad99Commented:
cdloves:

Glad to help.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 4
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now