需要c++ system()函数的帮助
Need assistancce with c++ sytem() functionn
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_type
是wchar_t
,因此path::string_type
相当于std::wstring
,并且path::c_str()
方法返回wchar_t*
。你不能将wchar_t*
赋值给std::string
,这就是编译器错误试图告诉你的。
要将path
对象赋值给std::string
,必须执行从wchar_t
到char
的字符转换。path::string()
方法为您做到了这一点,例如:
std::string s = i->string();
否则,使用std::wstring
代替,您可以使用path::native()
或path::wstring()
方法分配给它,例如:
std::wstring s = i->native();
std::wstring s = i->wstring();
相关文章:
- 需要帮助将结构数组传递给函数
- C++调用具有 *this 属性的单个帮助程序函数
- 用于检查值是否为其任何参数的帮助程序函数
- 无法将 2D 数组传递到 c++ 中的帮助程序函数中
- 在确定函数的时间复杂度时需要帮助
- C2783: 无法推断帮助程序函数的模板参数
- 友元函数需要一个帮助程序函数
- 在何处放置与类方法相关的帮助程序函数C++
- 需要帮助将字符串插入函数
- 从函数打印 CLI 帮助消息后,我应该如何干净地退出 C++ 程序?
- 类参数化与类和帮助程序函数混淆
- 需要有关在 C++ 中的函数 display() 上查找未定义引用的帮助
- 如何使用类中的函数从 main 打印变量,帮助理解 OOP c++
- 函数无法正常工作,调试器没有帮助
- 为什么这段代码不直接使用 C++ 幂函数?有人可以帮助我使用此代码中的电源函数吗?
- 函数和指针帮助:程序生成,但崩溃,没有任何特定错误
- 需要帮助理解 2D 数组并将其传递到函数中
- 重载模板函数帮助 - C++
- 调用模板化的成员函数:帮助我理解另一篇StackOverflow文章中的代码片段
- C++编程语法和函数帮助