简体   繁体   English

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

[英]C++ Pass a string into a pipe to gnuplot

I'm having a small problem passing a string to gnuplot from c++ I can pass integers easily enough, but when I try a string (user defined as "title" earlier in the code): 我在将字符串从C ++传递到gnuplot时遇到一个小问题,我可以很容易地传递整数,但是当我尝试一个字符串时(在代码前面的用户定义为“ title”):

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

I get the error: 我收到错误:

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

So instead I tried using: 因此,我尝试使用:

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

and the code actually compiled, but when I ran it I got the error from Gnuplot: 和实际编译的代码,但是当我运行它时,我从Gnuplot得到了错误:

line 0: undefined variable: h

Where "h" is just the test sting defined by "title". 其中“ h”只是由“ title”定义的测试字符串。

Does anyone have any ideas on how to pass this? 有谁对如何通过这个有任何想法吗?

Thanks in advance! 提前致谢!

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM