需要c++ system()函数的帮助

Need assistancce with c++ sytem() functionn

本文关键字:函数 帮助 c++ system 需要      更新时间:2023-10-16

ok,所以我写了一个程序,扫描所有目录和子目录以找到特定的文件扩展名(我传递一个字符串作为我想要的扩展名类型),然后它返回一个矢量加载,其中包含所有具有特定文件类型扩展名的文件名。然后我有另一个类,它有一个函数,打印出向量中的所有文件,然后迭代向量,并在用户选择的向量中运行一个程序。这是我的问题。从vvector获取要运行的文件。我在Windows 7上使用visual studio使用boost文件系统V3。这是我当前的功能:

#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

,这是我得到的错误:

错误1错误C2440: '初始化':无法从'const>boost::filesystem3::path::value_type *'转换为'std::basic_string<_Elem,_Traits,_Ax>'>c:usersadmindocumentsvisual studio 2010projectslauncherlaunchernotepad.h 31

在Windows上,path::value_typewchar_t,因此path::string_type相当于std::wstring,并且path::c_str()方法返回wchar_t*。你不能将wchar_t*赋值给std::string,这就是编译器错误试图告诉你的。

要将path对象赋值给std::string,必须执行从wchar_tchar的字符转换。path::string()方法为您做到了这一点,例如:

std::string s = i->string(); 

否则,使用std::wstring代替,您可以使用path::native()path::wstring()方法分配给它,例如:

std::wstring s = i->native(); 
std::wstring s = i->wstring();