如何解决如何使用 c++ 98
下面是一段代码,我试图从提供的目录路径中找到具有匹配模式的文件。
期望是列出所有模式匹配的文件, 例如在 "/usr/local" 路径下,存在以下文件 abc.txt axy.txt bcd.txt azz.txt bby.txt
abc.txt
axy.txt
azz.txt
#include <glob.h>
#include <string.h>
#include <vector>
#include <stdexcept>
#include <string>
#include <sstream>
#include <iostream>
using namespace std;
vector<string> glob(const string& pattern) {
// glob struct resides on the stack
glob_t glob_result;
memset(&glob_result,sizeof(glob_result));
// do the glob operation
//int return_value = glob(pattern.c_str(),globerr,&glob_result);
int return_value = glob(pattern.c_str(),GLOB_TILDE,NULL,&glob_result);
if(return_value != 0) {
globfree(&glob_result);
stringstream ss;
ss << "glob() Failed with return_value " << return_value << endl;
throw std::runtime_error(ss.str());
}
// collect all the filenames into a std::list<std::string>
vector<string> filenames;
for(size_t i = 0; i < glob_result.gl_pathc; ++i) {
filenames.push_back(string(glob_result.gl_pathv[i]));
}
// cleanup
globfree(&glob_result);
// done
return filenames;
}
int main(int argc,char **argv) {
vector<string> res;
res= glob("a");
return 0;
}
解决方法
正如评论中提到的,您只会匹配一个完全命名为 namespace DailyQuotes
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DailyQuote daily = new DailyQuote();
txtQuotee.Text = daily.Quoteee;
txtPeriod.Text = daily.GetPeriod();
txtQuote.Text = daily.DisplayQuote();
txtTime.Text = daily.Time.ToString("h:mm tt");
}
}
}
的文件,当您不应该匹配并抛出一个您没有捕获的异常时,您 a
。
globfree
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。