It is unclear from your example what “doesn’t work.” Are you having a compilation issue? Is an exception getting thrown?
It is also unclear where end_itr is defined. Could you provide a more complete example?
Dan
From: Boost-users [mailto:boost-users-bounces@lists.boost.org]
On Behalf Of Sarma Tangirala
Sent: Tuesday, June 25, 2013 20:56
To: boost-users@lists.boost.org
Subject: [Boost-users] Problem Iterating a directory
Hello,
I am using boost filesystem to iterate through my directory and have encountered a problem that I am unsure of how to debug.
try {
//for ( boostfs::directory_iterator dir(boostfs::path("/home/vtangira/Desktop/person_finder_v20130513/data/dummy1")), end_itr;
for ( boostfs::directory_iterator dir(boostfs::path(paths_to_files.at(0).c_str())), end_itr;
dir != end_itr;
dir++
) {
std::cout << "File: " << dir->path() << std::endl;
}
} catch (boostfs::filesystem_error e) {
cout << "Error Code: " << e.code() << endl
<< "Error Msg: " << e.code().message() << endl;
}
In this snippet, the line with the for loop that has been commented out works but the the one below it with the vector does not. The vector version represents the same string.
Any advice is appreciated.
Thanks
--
0 1 0
0 0 1
1 1 1