I'm writing a program which use the <string>, <vector> and <ifstream>
classes.
Given an array of string, i.e vector<string> file_names, example :
file_names[0] = "file1.txt"
file_names[1] = "file2.txt"
etc ...
I want to do a for-loop and read the content of all of this files, I
started with (n_file is the size of the dynamical allocated array
file_names) :
for (in_file = 0; in_file < n_file; ++in_file)
{
ifstream file(file_names[in_file],ios::in);
// here the data handling of the content of the file
file.close();
}
It doesn't work, I get a message error during the compiling process
(gnu gcc comiler on linux) :
opt_main.c++:261: error: no matching function for call to `
std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(
std::string&, const std::_Ios_Openmode&)'
/usr/local/bin/gcc3_3/include/c++/3.3/iosfwd:89: error: candidates
are:
std::basic_ifstream<char, std::char_traits<char>
::basic_ifstream(const
std::basic_ifstream<char, std::char_traits<char> >&)
/usr/local/bin/gcc3_3/include/c++/3.3/fstream:519: error:
std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const char*,
std::_Ios_Openmode = std::ios_base::in) [with _CharT = char,
_Traits =
std::char_traits<char>]
/usr/local/bin/gcc3_3/include/c++/3.3/fstream:504: error:
std::basic_ifstream<_CharT, _Traits>::basic_ifstream() [with _CharT
= char,
_Traits = std::char_traits<char>]
It's (I guess) probably due to the use of a string or the absence of
quotes in :
ifstream file(file_names[in_file],ios::in);
I've tested instead ifstream
file("\""+file_names[in_file]+"\"",ios::in), the quotes are then
present in the string but It still doesn't work.
I've checked that ifstream file("file1.txt",ios::in) is OK for (one
after the others) all the files.
If soeone has got an idea ...
Thanks in advance
Herve