开发者

C++, Ifstream opens local file but not file on HTTP Server

开发者 https://www.devze.com 2023-02-04 07:46 出处:网络
I am using ifstream to open a file and then read from it. My program works fine when i give location of the local file

I am using ifstream to open a file and then read from it. My program works fine when i give location of the local file on my 开发者_如何学JAVAsystem. for eg /root/Desktop/abc.xxx works fine

But once the location is on the http server the file fails to open. for eg http://192.168.0.10/abc.xxx fails to open.

Is there any alternate for ifstream when using a URL address?

thanks.


There are no utilities in the standard C++ library for accessing data via http protocol.

There are 3rd-party libraries though: Libwww libcurl

Another option is to have a virtual filesystem that maps remote http files as local files. This way you don't have to modify your application to access http. Something like http://okmij.org/ftp/HTTP-VFS.html


ifstream will not read files off of an HTTP Server. It will only read local files.


The f in ifstream is for file, not socket.

You need to make an HTTP GET Request and then stream the response, this is a totally different operation.

Consider using boost::asio, or similar. [Examples]

Update

Since the web server is on your local area network (judging by the IP address - not sure why people still insist in using those in these heady days of DNS, but that's by the by), you could probably mount the filesystem containing the desired file on your local machine, using NFS or similar. Then you'd be able to perform file operations, such a reading with ifstream.


ifstream only works with files accessible on the filesystem, not on web servers.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号