小编iNu*_*ste的帖子

在 C 中使用 Glob() 列出目录中的文件

基本上,到目前为止我有这个代码:

#include <glob.h>
#include <string.h>
#include <stdio.h>

# define ERROR 1
# define FAILURE -1

int main(int ac, char **av)
{
  glob_t globlist;
  int i;

  i = 0;               
  if (ac == 1)
    return (-1);
  else
    {
      if (glob(av[1], GLOB_PERIOD, NULL, &globlist) == GLOB_NOSPACE
          || glob(av[1], GLOB_PERIOD, NULL, &globlist) == GLOB_NOMATCH)
        return (FAILURE);
      if (glob(av[1], GLOB_PERIOD, NULL, &globlist) == GLOB_ABORTED)
        return (ERROR);
      while (globlist.gl_pathv[i])
        {
          printf("%s\n", globlist.gl_pathv[i]);
          i++;
        }
    }
  return (0);
}
Run Code Online (Sandbox Code Playgroud)

例如,当我键入时./a.out "*",它会打印我所在的所有文件以及目录,但不会打印目录内的内容。我应该如何打印所有文件,包括子文件/文件夹?

谢谢

c unix linux glob path

3
推荐指数
1
解决办法
1万
查看次数

线程传染媒介在C++的

我正在尝试使用线程向量.我将收到一个int作为参数,这将是我将要创建的线程数.

我试过这样的事情:

#include <iostream>
#include <thread>
#include <vector>

void credo()
{
    std::cout << "threads" << std::endl;
}

void threads_creation()
{
    int i;
    std::vector<std::thread> threads_tab;
    i = 0;
    while(i < 2)
    {
        threads_tab.push_back(std::thread(credo));
        i++;
    }
}

int main()
{
    threads_creation();
    return (0);
}
Run Code Online (Sandbox Code Playgroud)

但是我得到了这个编译错误:

/tmp/ccouS4PY.o: In function `std::thread::thread<void (&)()>(void (&)())':
threads.cpp:(.text._ZNSt6threadC2IRFvvEJEEEOT_DpOT0_[_ZNSt6threadC5IRFvvEJEEEOT_DpOT0_]+0x21): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

通过使用以下命令进行编译:

g++ -W -Wall -Werror -Wextra threads.cpp
Run Code Online (Sandbox Code Playgroud)

这有什么不对?

c++ multithreading vector

1
推荐指数
1
解决办法
524
查看次数

标签 统计

c ×1

c++ ×1

glob ×1

linux ×1

multithreading ×1

path ×1

unix ×1

vector ×1