3
I have the following situation, a file "tables.txt" where I have around 2000 lines with filename to which I want to pass row by row taking the name of the files and check which ones exist and which ones not.
The problem occurs when after catching the file name to be checked try to pass it to open it later ifstream obj (arq)
, the strange thing is that if I type passing the string with the path and not the variable arq
that is string the file is read smoothly.
Follows the code used:
#include <iostream>
#include <fstream>
#include <string>
#include <string>
using namespace std;
int main () {
string line;
ifstream myfile ("tabelas.txt");
if (myfile.is_open()){
while (! myfile.eof() )
{
getline (myfile,line);
string arq = "..\\dados\\"+ line+".csv";
ifstream obj (arq);
if (!obj)
cerr<<"Ocorreu um erro ao abrir o arquivo"<<endl;
}
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
Follows image demonstrating error:
I could not reproduce the http://ideone.com/VCbQyoerror
– Maniero
are using which IDE? I am using Dev-C++
– Lucas Monteiro
I have not used any IDE, it does not matter. http://answall.com/q/101691/101
– Maniero
I understand the difference between the terms, but I’ve seen an error in dev c which did not happen in Code::Blocks, it was more of curiosity. I tried several ways and it was not possible, I ended up doing in python however, if possible I would like to know how to do in C++ too, you have some other way(eg another function) that I can get the result I seek?
– Lucas Monteiro