Attached, those tests you asked.
Headers:
1 2 3 4 5
|
#include <iostream>
#include <vector>
#include <fstream>
#include <ctime>
#include <string>
|
we did the corrections about the unneeded .c_str(); in 5,6,7,12.
we modified the code to print an output between [], to check where it is going wrong.
As we said the file modelos.txt was successfully opened. In windows we did not have any trouble but in linux something is weird.
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
|
int main(int argc, char* argv[])
{
string pasta = "data/";
string fnamestr="exemplo1.dat";
ifstream arquivoModelos(string(pasta + "modelos.txt"));
ifstream teste1;
ifstream teste2;
string nomeArquivo;
while (getline(arquivoModelos, nomeArquivo)) {
cout << "Executando arquivo: [" << nomeArquivo << "]" << endl;
cout << "Executando arquivo: [" << fnamestr << "]" << endl;
teste1.open(nomeArquivo); // this one is not working
if(teste1)
cout << "File opened - while reading name from file" << endl;
else
cout << "Error openning file - while reading name from file" << endl;
teste2.open(fnamestr); // this one is working
if(teste2)
cout << "File opened - while reading name from declared variable" << endl;
else
cout << "Error openning file - while reading name from declared variable" << endl;
}
cout << "Final do processamento.\n";
//getch();
return 0;
}
|
The given output was:
https://ibb.co/mxO1Lq
We noticed that the output for the string read from the file and the string read declared directly was different.
]xecutando arquivo: [exemplo1.dat <--- We think something is happening here.
Executando arquivo: [exemplo1.dat] <--- This one is opening the file normally.
The text in the file modelos.txt has not format, it is plain and it has anything at the end of line. So, this error is not making any sense to us.
https://ibb.co/haecRV
David