gpt4 book ai didi

C++将字符串传递到管道中以传递给gnuplot

转载 作者:行者123 更新时间:2023-11-28 06:13:28 26 4
gpt4 key购买 nike

我在从 C++ 向 gnuplot 传递字符串时遇到了一个小问题,我可以很容易地传递整数,但是当我尝试一个字符串(用户在代码前面定义为“title”)时:

fprintf(gnuplotPipe, "set title %s\n", title);

我得到错误:

error: cannot pass objects of non-trivially-copyable type ‘std::string {aka class std::basic_string<char>}’ through ‘...’

所以我尝试使用:

fprintf(gnuplotPipe, "set title %s\n", title.c_str());

并且代码实际编译了,但是当我运行它时,我收到了来自 Gnuplot 的错误:

line 0: undefined variable: h

其中“h”只是“title”定义的测试字符串。

有没有人知道如何通过这个?

提前致谢!

最佳答案

您必须将标题放在引号中:

fprintf(gnuplotPipe, "set title \"%s\"\n", title.c_str());

关于C++将字符串传递到管道中以传递给gnuplot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30763939/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com