Concatenate string from text file

Hi

mY files paths are defined as :

//sbase = 'D:\data\sample_AMC\fasta_files\';
sbase2 = 'D:\data\sample_AMC\fasta_files\results\';
snameprefix = 'orig_ind';
snameprefix3 = 'results_ind';

...
const string filname = sbase + snameprefix  + snamesuffix;
const string resultsname_ = sbase2 + snameprefix3  + snamesuffix;

This concatenation works perfectly fine when i have to manually defines the samplesnames

However now I have 98 such samples names to work with.This implies I have to keep updating my sbase and sbase2 98 times.

If my sample name changes from sample_AMC to sampleABC_123 then I have to update the path manuallyto

sbase = 'D:\data\sampleABC_123\fasta_files\';
sbase2 = 'D:\data\sampleABC_123\fasta_files\results\';

In order to make it easier,I saved all my 98 samplename entries in a text file.

text file looks like this
sample_AMC
sampleABC_123
sampeBMC
sampleQWE

Is there a way I could read string entries line by line from a text file using c++ and concatenate it to sbase and sbase2?

Yes you can read an entire line of sample names from an input file into a string variable...open the input file and loop through it a line at a time while reading the sample names into a string variable "sbase" with the getline function...

ifstream fin;
string sbase;
fin.open("input_file.txt");
while (!(fin.eof())) {
    getline(fin, sbase);
    .
    .
    .
}
sbase2 = 'D:\data\sample_AMC\fasta_files\results\';
snameprefix = 'orig_ind';
snameprefix3 = 'results_ind';

This looks wrong. ' in C/C++ means character, not string. It's possible, though strange, to have a really long character, but almost certainly not what you intended.

Also, \ needs to be escaped inside ' and " alike.

sbase2 = "D:\\data\\sample_AMC\\fasta_files\\results\\";
...