read / write txt files on the internet

Hi friends, first of all I would like to apologize for my bad English ... it's not my mother tongue and I'm using an online translator.
I have some code that can read and write to a txt file and move the words into string variables.
if the file is on my computer, it works. but if the file was on the internet, how could I do?
(for example http://www.mysite.com/file.txt)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <fstream>

using namespace std;

int main() {
char x[10];
char y[10];

fstream filei;
fstream fileo;

filei.open("file.txt");
if(!filei) {
cout << "error in reading the file";
return 1;
}

filei >> x >> y;
filei.close();

cout <<"the first word is: "<< x <<endl;
cout <<"the second word is: "<< y <<endl;

return 0;
}


Thank you so much
If you use windows you can have a look at the Windows API.
https://msdn.microsoft.com/en-us/library/sb35xf67.aspx

Otherwise you have to look for a library.
https://stackoverflow.com/questions/24901977/c-and-internet-program
I forgot to tell you, yes I use windows.
before asking for help to you I tried a lot, and I found a lot of information but probably I'm not good enough to use them ....
would it be very complicated to give me an example ready to be used? I do not know how you can solve ...
Here is how to download a file from an urkl.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <string>
#include <fstream>
#include <Urlmon.h> // URLDownloadToFileA
#include <cstdio> // perror, errno

#pragma comment(lib, "Urlmon.lib")

using namespace std;

int main()
{
  const string url = "http://www.cplusplus.com/forum/beginner/232619/";
  const string target = "website.html";

  cout << "\nDownloading, please wait......\n";
  // https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/ms775123(v=vs.85)
  HRESULT res = URLDownloadToFileA(nullptr, url.c_str(), target.c_str(), 0, nullptr);

  if (res == S_OK)
  {
    cout << "\nDownload finished.\n";
    // lets to to display the downloaded file
    ifstream src(target);
    if (!src)
    {
      perror(nullptr);
      return errno;
    }
    cout << "Content of " << url << "\n\n";
    string line;
    while(getline(src, line))
      cout << line << "\n";
  }
  else
  {
    cout << "\n\aSome error occured.....";
  }
}


If you don't use Visual Studio you need to add Urlmon.lib to your project.

To upload a file is more difficult. On most servers you need a ftp url, username and password.
Thanks friend! I am moved by your willingness to help me.
I owe you.
Topic archived. No new replies allowed.