ok so i wrote a program which scaans all directories an sub directories to find sepcific file extensions(i pass a string for the extension type i want) then it returns a vector loade with all the filenames with the specific filetype extensions. then i have another class which has a function that print out all of the files in the vector and will then will iterate the vector and run a program in that vector that the user chooses. This is my problem. Getting the file from the vvector to run. i am using visual studios on windows 7
using boost filesystem V3. this is my current function:
#define BOOST_FILESYSTEM_NO_DEPRECATED
#ifndef NotePad__h
#define NotePad__h
#include boost/filesystem.hpp
#include iostream
#include io.h
#include stdlib.h
#include stdio.h
#include cstdlib
#include Windows.h
#include atlstr.h
#include string
#include cstring
;
namespace fs = boost::filesystem;
class NpLaunch
{
public:
void Launch (const std::vector<fs::path>& v)
{
int count=0;
std::cout << "launched in notePad.h" << std::endl;
for(auto i = v.begin(); i!= v.end(); ++i)
{
//string s;
//string val = (string) itr;
std::cout << count << ". " << *i << std::endl;
++count;
std::string s = i->c_str();
//std::system(i->c_str());
}
}
};
#endif
and this is the error im getting:
Error 1 error C2440: ‘initializing’ : cannot convert from ‘const >boost::filesystem3::path::value_type *’ to ‘std::basic_string<_Elem,_Traits,_Ax>’ >c:\users\admin\documents\visual studio 2010\projects\launcher\launcher\notepad.h 31
On Windows,
path::value_typeis awchar_t, and thuspath::string_typeis equivilent tostd::wstring, and thepath::c_str()method returns awchar_t*. You cannot assign awchar_t*to astd::string, that is what the compiler error is trying to tell you.To assign a
pathobject to astd::string, you have to perform a character conversion fromwchar_ttochar. Thepath::string()method does that for you, eg:Otherwise, use a
std::wstringinstead, which you can assign to using either thepath::native()orpath::wstring()method, eg: