将整数值传递给系统调用命令
Passing integer value to system evoking command
有人可以告诉我如何将整数值传递给命令语句吗?
int lf,ff;
string cmd,filename;
cmd = "catdcd -o -otype frame.xyz -first "+lf+" -last "+ff+" "+filename+"";
system((cmd).c_str());
错误:类型不匹配"const __gnu_cxx::__normal_iterator<_Iterator、_Container>"和"int">
我刚刚尝试使用...
cmd = "catdcd -o -otype frame.xyz -first "lf" -last "ff" "+filename+"";
但最终又出现了另一个错误。
错误:无法将参数"1"的"std::string {aka std::basic_string}"转换为"char*"到"int sprintf(char*, const char*, ...(">
请帮忙。我必须增加lf
的值,并为我的程序使用循环ff
。
我对C++相当陌生,所以我不知道这样做的最佳方法是什么,但这应该有效。
#include<sstream>
stringstream ss;
ss << "catdcd -o -otype frame.xyz -first " << lf << " -last " << ff << " " << filename;
string cmd = ss.str();
如果您使用的是C++ 11,则可以使用to_string()
函数,因此类似于
int lf, ff;
string cmd, filename;
cmd = "catdcd -o -otype frame.xyz -first " + to_string(lf) + " -last " + to_string(ff) + " " + filename + "";
system((cmd).c_str());
应该做这项工作。
相关文章:
- 有什么好的方法可以让系统调用代理允许在单元测试中进行模拟
- 如果整个应用程序是虚拟映射的,为什么 new 会进行系统调用?
- 如何将C++系统调用连接到 freertos
- 如何使用 C/C++ 和 system() 系统调用以外的其他方法在 Linux 中获取文件功能?
- 系统调用:一次和多次,哪个更好?
- 使用路径和空格的系统调用
- 是否有等效于 macOS 上的 clone() 系统调用?
- 从C++调用系统调用节点?
- 读取系统() 命令错误响应消息
- C++测试程序中的非法系统调用(对角矩阵元素程序的总和)
- 将 Linux system() 调用命令的输出重定向到仅可变的
- 英特尔 Pin:如何获取系统调用的返回地址
- 如何使用低级系统调用从 stdin 和输入文件中获取字节数
- 使用模拟器C++从RISC-V裸机程序调用printf系统调用时失败
- 为什么除了最后一帧之外,每一帧都没有调用命令
- 动态执行的 ARM ASM 系统调用,可从C++重新定位
- 如何知道我正在使用的Linux OS是否具有特定的系统调用
- 当C 中的系统调用conconculables时,参数字符串中的字符损失
- 调用系统调用函数时出现异常
- 将整数值传递给系统调用命令