【问题标题】:Using pipes inside a class in C++在 C++ 中的类中使用管道
【发布时间】:2010-04-16 22:12:45
【问题描述】:

我正在尝试使用 this 教程在 C++ 中使用 Gnuplot 制作绘图。但是我将在一个类中使用管道连接到 Gnuplot,但后来我遇到了一些问题:

我有一个头文件,其中声明了所有变量等。我也需要在这里声明pipe-变量,但我该怎么做呢?

我试过直接做,但是没用:

记录器.h:

class Logger {
    FILE pipe;
}

Logger.cpp:

Logger::Logger() { //Constructor
    *pipe = popen("gnuplot -persist","w");
}

给出错误Logger.cpp:28: error: no match for ‘operator=’ in ‘*((Logger*)this)->Logger::pipe = popen(((const char*)"gnuplot -persist"), ((const char*)"w"))’

建议?

【问题讨论】:

    标签: c++ file class pipe


    【解决方案1】:

    您的 FILE 必须是指向 FILE 的指针

    FILE *pipe;

    然后

    pipe = popen(...)

    【讨论】:

    • 用 *pipe 试过,但它给出了与上面提到的相同的错误。
    • 更新:我的错。现在工作。非常感谢! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-30
    • 2011-07-16
    • 1970-01-01
    • 1970-01-01
    • 2013-11-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多