I'm trying to read a file containing over 10.000 lines and each line contains an ID for an individual and a very long string composed of more than 1 million characters (numbers as example: `2200500200...205` until 1 million characters long). 

I need to go through this long string and retrieve a subset based on flag information formed by 0 or 1s coming from a string called `flagArray01String` in the sample code, so I'm checking one string of the same length and printing the subset in a file. 

I'm in doubt if I should convert the long strings (string from file and string composed of flags) to char and perform the loop after that. I'm looking forward to receiving any comments that could help me obtaining a better performance. 

Should I load all the strings in memory for some individuals? Are there any other performance tricks?

---

Example of a sample file:

```
ID1 2020205000200200202020
ID2 2020205000200200202020
ID3 2020205000200200202020

...
ID10000 2020205000200200202020

```

Example of flag:
flag = `1000001111111111111100`, where all the positions with 1´s should be retrieved and printed in a separated file.

---

```
if (IN_file.is_open()) 
{
    getline(IN_file, headerFileOriginal);
    while (IN_file >> idOriginal >> longString) 
    {
        sizeTemp = longString.size();
        if (sizeTemp > 0)
            numbIdsOriginal++;
        for (int p = 0; p < flagArray01String.size(); p++) 
        {
            if ((flagArray01String[p] == '1')) 
            {
                subsetString = subsetString + longString[p];
            }
        }
        OUT_FILE << idOriginal << '\t' << subsetString << endl;
        subsetString = "";
    }
} 
else 
{
    myfileLog << "Problems to open file " << IN_file_StringName << endl;
    cout << "Problems to open file " << IN_file_StringName << endl;
}

IN_file.close();
OUT_FILE.flush();
OUT_FILE.close();

```