C++ ifstream对于不使用';不存在
我想做什么? < >我正在创建一个C++程序,我检查文件是否存在,用于CWD(当前工作目录)中的命令执行,如果不是bin,如果没有,那么sbin文件夹。< /p> 我在做什么? 我正在使用ifstream检查应用程序是否存在。如果创建对象,我认为它是有效的。否则我不会。下面是我所做工作的代码示例C++ ifstream对于不使用';不存在,c++,ubuntu,login,ifstream,C++,Ubuntu,Login,Ifstream,我想做什么? < >我正在创建一个C++程序,我检查文件是否存在,用于CWD(当前工作目录)中的命令执行,如果不是bin,如果没有,那么sbin文件夹。< /p> 我在做什么? 我正在使用ifstream检查应用程序是否存在。如果创建对象,我认为它是有效的。否则我不会。下面是我所做工作的代码示例 string pathforCWD = argv[1]; ifstream checkFileCWD(pathforCWD.c_str()); if (!checkFileCWD) {
string pathforCWD = argv[1];
ifstream checkFileCWD(pathforCWD.c_str());
if (!checkFileCWD) {
cout << "\nCommand not Found in working directory\n";
cout<<endl<<"";
string pathforBin = "/bin/",argv[1];
ifstream checkFileBin(pathforBin.c_str());
if(!checkFileBin)
{
cout<<"\nCommand also not found in Bin\n";
string pathforSbin = "/sbin/",argv[1];
ifstream checkFileSbin(pathforSbin.c_str());
if(!checkFileBin)
{
cout<<"\nFile also not found in sBin\n";
}
else
{
cout<<"\nCommand found in SBin directory.. Executing it."<<endl;
int response = system((orignalCommand).c_str());
programExecution(response);
}
}
else
{
cout<<"\nCommand found in Bin directory.. Executing it."<<endl;
int response = system((orignalCommand).c_str());
programExecution(response);
}
} else {
cout<<"\nCommand found in working directory.. Executing it."<<endl;
int response = system(("./" + orignalCommand).c_str());
programExecution(response);
}
stringpathforcwd=argv[1];
ifstream checkFileCWD(pathforCWD.c_str());
如果(!checkFileCWD){
cout以下定义与您认为的不一样:
string pathforBin = "/bin/",argv[1];
提示:您在此处声明了两个名称,pathforBin
和argv
以下定义与您认为的不同:
string pathforBin = "/bin/",argv[1];
提示:您在此处声明了两个名称,pathforBin
和argv
以下定义与您认为的不同:
string pathforBin = "/bin/",argv[1];
提示:您在此处声明了两个名称,pathforBin
和argv
以下定义与您认为的不同:
string pathforBin = "/bin/",argv[1];
提示:您在这里声明了两个名称,pathforBin
和argv
可能重复的非重复项..检查答案..可能重复的非重复项..检查答案..可能重复的非重复项..检查答案..先生,这真是一个愚蠢的错误克…谢谢…谢谢…谢谢…先生,这是一个非常愚蠢的错误…谢谢…谢谢…先生,这是一个非常愚蠢的错误…谢谢…谢谢…谢谢…先生,这是一个非常愚蠢的错误…谢谢…谢谢。。