I have a text file, for example:

This
Is
A
Text
File

This file is on some host.

Now I want to get the file to my program, my problem here is, that I found how to save the file(download) but that's not what I need..
I need it to be in a variable inside my program, for example, the text above should be in a char array and look something like this:

This\nIs\nA\nText\nFile

I tried to play around with cURL but didn't succeed.

I hope someone can help me with that.

You say that you have found out how to download a file, but that this isn't what you need. I would argue that downloading the file would be a good start. Once the file is on your computer you can read/write to the file very easily using ifstream and get. Then you can delete the file when you don't need it. Think about your web browser. Whenever it wants to use a file (pdf/jpg/etc) it downloads it into a temporary cache and then opens the file(s) from there.

So download it into a temp file and then you can:

#include <fstream>

using namespace std;

int main()
{
   ifstream mydata;
   //Change the pathname to wherever the file is of course
   mydata.open("/home/user/tempfile"); 
  
   //Now you can use a loop enter your data into an array, vector, string, whatever
   //Example
   char a;
    mydata.get(a); //Grab a single character from the file
    string b;
    mydata >> b; //Grab a string from the file

   ....
}

Well, the reason I asked this question is that I don't want a temp file.
If I wanted to use a temp file I would do that instead of posting a thread here..

You might want to implement your own HTTP client. In Visual, you've got CAtlHttpClientT with a number of methods for extracting either raw response data or even structured header/body.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.