-4

I'm currently working on a C++ project to get the price of my stocks, and display it in cells on my computer screen. However, my Googling is NOT working for any of this. I also searched for libraries, but to no avail. Can anyone please tell me how I can do this? I don't know how to use the Google and Yahoo APIs, so maybe they could use some help. I need something so I can put in my code, like:

this->label1->Text = stockPrice;

The main thing about this is to get the live prices of my stocks and display it on my computer in cells or graphs.

So, thanks!

1 Answers1

1

I suspect questions like this get voted down because they're rather repetitious. Still, for someone new to C++/CLI it's helpful to see working example code. In the example below we're using the Yahoo service--look at the URL closely and figure it out, otherwise search the web for further fun an profit to learn how to use their API:)

#include "stdafx.h"

using namespace System;
using namespace System::IO;
using namespace System::Net;
using namespace System::Text;

int main(array<System::String ^> ^args)
{
    HttpWebRequest^ myRequest = dynamic_cast<HttpWebRequest^>(WebRequest::Create( "http://ichart.finance.yahoo.com/table.csv?s=MSFT&a=1&b=1&c=2011&d=1&e=1&f=2011&g=d&ignore=.csv" ));

    myRequest->Method = "GET";
    WebResponse^ myResponse = myRequest->GetResponse();

    Stream^ receiveStream = myResponse->GetResponseStream();
    StreamReader^ sr = gcnew StreamReader( receiveStream,Encoding::UTF8 );

    Console::WriteLine(sr->ReadToEnd());

    sr->Close();
    myResponse->Close();

    return 0;
}
Geoffrey McGrath
  • 1,513
  • 1
  • 13
  • 31