小编Bre*_*een的帖子

未找到 c++11 上的 popen

我正在尝试以可移植的方式从 C++ 程序运行 gnuplot。具有讽刺意味的是,对于 WIN_32 我没有问题,但我的编译器(Visual Studio 2015)无法识别我尝试用于其他操作系统的 POSIX 命令 popen() 。C++11 中 popen() 不存在吗?是否有等效项或者我必须更改标准?

这在 Windows Visual Studio 2015 中编译并运行:

#include <stdio.h>
#include <stdlib.h>

int main()
{
  _popen(" ", "w");
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

这不能编译:

#include <stdio.h>
#include <stdlib.h>

int main()
{
  popen(" ", "w");
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

错误错误 C3861 'popen':
一天结束时未找到标识符,我想要类似的行为

#include <stdio.h>
#include <stdlib.h>

int main()
{
  #ifdef WIN_32
    _popen(" ", "w");
  #else
    popen(" ", "w");
  #endif
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

我希望这个程序在 Linux 和 Mac 上使用时可以用 g++ 重新编译,但我想在 Windows …

popen c++11 visual-studio-2015

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

标签 统计

c++11 ×1

popen ×1

visual-studio-2015 ×1