hi i was wondering if there is a way i can use ifstream to read from a web page and how i would do this at a guess
im pretty sure this is wrongCode:ifstream ins("www.webpage.com");
thanks in advance
hi i was wondering if there is a way i can use ifstream to read from a web page and how i would do this at a guess
im pretty sure this is wrongCode:ifstream ins("www.webpage.com");
thanks in advance
you'd probably want to check the networking forum, I'm sure there's a way but you probably need some sort of protocol libarary. I'm just guessing though.
ok cool ty ill start a thread there or can this one be moved?
To the best of my knowledge, no one has written a TCP, HTTP, or any other kind of internet stream and made it publically available.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
well if there is a gap in the market maybe you should consider trying to make one?
im gonna research the web again and see if i can find anything there
thanks
You could create a class of your own and use some simple function like URLDownloadToFile() to download the source or the webpage to a file then make it read that file, save its info to memory somewhere ... I think there shoudl be an example of URLDownloadToFile somewhere on the boards.
No, the iostream interface is too unflexible for any serious net communication to be done over it.Originally Posted by stien
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
if i post this link you can see what information i need from the web site
but where it says zezima u will be able to put any name you want but im sure ill work that out just need to get that info
http://hiscore.runescape.com/lang/en/aff/runescape/hiscorepersonal.ws?user1=zezima
this has the info i need for my program im sure ill be able to parse the data t omy program but i would have no idea how to make that class work?
twomers if u could maybe point me in the right direction or give me a link to where i can find out how to get the webpage to download to my program i would appreciate it very much
and again thank you
Last edited by stien; 01-20-2007 at 05:35 AM.
Sure I'll go one better, here's some source:
You're gonna have to wait for the file to download properly though.Code:#include <iostream> #include <string> #include <fstream> #include <urlmon.h> #pragma comment( lib, "urlmon.lib" ) class URLstream { private: std::string PageURL; std::string PageSource; HRESULT ReturnValue; void ReadFile ( void ); public: URLstream( void ); URLstream( std::string n_PageURL ); bool open( std::string n_PageURL ); void getpage( void ); friend std::istream &operator >> ( std::istream &in, URLstream &instance ); friend std::ostream &operator << ( std::ostream &out, URLstream &instance ); }; void URLstream::ReadFile( void ) { std::ifstream in ( "tmp.tmp" ); std::string tmp; if ( in ) while ( std::getline( in, tmp ) ) PageSource += tmp + "\n"; in.close(); } URLstream::URLstream( void ) : ReturnValue( 0 ) {} URLstream::URLstream( std::string n_PageURL ) : PageURL( n_PageURL ), ReturnValue( 0 ) { open( PageURL ); } bool URLstream::open( std::string n_PageURL ) { PageURL = n_PageURL; ReturnValue = URLDownloadToFile( NULL, PageURL.c_str(), "tmp.tmp", 0, NULL ); if ( ReturnValue == E_OUTOFMEMORY ) return false; ReadFile(); return true; } std::istream &operator >> ( std::istream &in, URLstream &instance ) { in >> instance.PageURL; instance.open( instance.PageURL ); return in; } std::ostream &operator << ( std::ostream &out, URLstream &instance ) { return out << instance.PageSource; } int main( void ) { URLstream URL; std::cout<< "Enter the URL: "; std::cin >> URL; std::cout<< URL; return 0; }
EDIT: You're probably going to have to put in the whole address. with the http:// etc. The checking I put in there was minimal so you should put in more, and more functions too.
Last edited by twomers; 01-20-2007 at 08:08 AM.
hey thanks alot i really appreciate it.
at a quick glance i thinks its gone straight over my head but ill read through and study it properly. im sure that is just what i need
thank you
ok the first thing i dont understand is the <urlmon>
and the urlmon.lib
are these files included with my compiler? i use devcpp 4.9.8.0
Last edited by stien; 01-20-2007 at 03:55 PM.
Don't mention it. I like to give code every now and then
Have you tried compiling it? I honestly don't know if they are included in dev or not. I wrote it using .... erm ... MSVC 2003 I think. the urlmon thing is just a library. Try compiling the code.
i compiled it but it says no such direcotry.
but when i compiled as .h
it worked?
You talking about the urlmon? That's meant to have a .h ... Is the code what you were looking for? You should probably split it into a .h and .cpp to make it more ... ethically correct. So it works?
sorry i ment the code you wrote for me didnt compile when i saved it as url.cpp
but it did compile when i saved it as url.h
i just googled urlmon.h but i couldnt find any place to download it from have you got any ideas where i could find it?
Last edited by stien; 01-20-2007 at 04:17 PM.
None I'm afraid. Perhaps that free MSVC thing that people are downloading ... can't remember what it's called. But that's not a guarantee! Hopefully someone else will know.