I'm having trouble getting this to work, I've been beating my head against the wall for about two or three days now, reading through the boost docs and whatnot, and having absolutely no luck with it. What I'm trying to do is recursively open every file in a save/ directory, and read in a new class to a vector.
void characterSet::openChars(){
vector<boost::filesystem::path> v;
vector<boost::filesystem::path>::iterator iter;
const boost::filesystem::path p("save/");
try{
if(exists(p) && is_directory(p)){
copy(boost::filesystem::directory_iterator(p), boost::filesystem::directory_iterator(), back_inserter(v));
sort(v.begin(), v.end());
for(iter = v.begin(); iter != v.end(); ++iter){
myOpenFile.open(iter->filename()); //This line is broken
it = characters.begin();
while(!myOpenFile.eof()){
myOpenFile >> name;
for(int i = 0; i < 9; i++){
myOpenFile >> tempInt;
x.push_back(tempInt);
}
tempChar = new character(name, x);
cout << "Successfully loaded " << tempChar->charName << endl;
characters.push_back(tempChar);
x.clear();
}
myOpenFile.close();
}
}
else {cout << p << "does not exist.\n";}
}
catch(const boost::filesystem::filesystem_error& ex){
cout << ex.what() << "\n";
}
}
The problem I'm getting is that the compiler throws an error to me:
/home/*****/Documents/OOP/*****/main.cpp||In member function ‘void characterSet::openChars()’:|
/home/*****/Documents/OOP/*****/main.cpp|143|error: no matching function for call to ‘std::basic_ifstream<char, std::char_traits<char> >::open(boost::filesystem3::path)’|
/usr/include/c++/4.4/fstream|525|note: candidates are: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]|
||=== Build finished: 1 errors, 0 warnings ===|
For some reason that I can't tell, I can't get the file to compile. I think it's a typecast issue, and I tried using stringstream to fix it, but that didn't work out well. Everything past the commented line has been tested independently to work. Any other ideas?
Yes, the documantion i've read stated that the return type is 'string_type'. But from the error it looks like it returns 'path'. Then you have to write myOpenFile.open(iter->filename().string().c_str());