C命令行参数Eclipse CDT?

我使用这个代码 http://sicktoolbox.sourceforge.net/>的示例程序 http://sourceforge.net/projects/sicktoolbox/files/.它基本上是距离扫描仪驱动程序.我试图运行的程序是在sicktoolBox-1.0.1 / c / examples / lms / lms_plot_values中,以防你想看到我在说的代码.

无论如何,lms_plot_values项目文件夹包含gnuplot_i.cc,gnuplot_i.hpp,main.cc,Makefile,Makefile.am,Makefile.in.所以我把前三个文件放在我的Eclipse Indigo CDT中,编译(没有编译器错误,所有在Eclipse中已经正确连接的所有库都添加了),但是这个示例程序是用来写入命令行参数的.这是代码获得的一切.

/*!
 * \file main.cc
 * \brief Illustrates how to acquire a measurements from the Sick
 *        LMS 2xx using the configured measuring mode.
 *
 * Note: This example should work for all Sick LMS 2xx models.
 *
 * Code by Jason C. Derenick and Thomas H. Miller.
 * Contact derenick(at)lehigh(dot)edu
 *
 * The Sick LIDAR Matlab/C++ ToolBox
 * copyright (c) 2008,Jason C. Derenick and Thomas H. Miller
 * All rights reserved.
 *
 * This software is released under a BSD Open-Source License.
 * See http://sicktoolBox.sourceforge.net
 */

/* Implementation dependencies */
#include <stdlib.h>
#include <string>
#include <vector>
#include <signal.h>
#include <iostream>
#include <sicklms-1.0/SickLMS.hh>
#include "gnuplot_i.hpp"

using namespace std;
using namespace SickToolBox;

bool running = true;
void sigintHandler(int signal);

int main(int argc,char * argv[]) {

  string device_str; // Device path of the Sick LMS 2xx
  SickLMS::sick_lms_baud_t desired_baud = SickLMS::SICK_BAUD_38400;

  /* Check for a device path.  If it's not present,print a usage statement. */
  if ((argc != 2 && argc != 3) || (argc == 2 && strcasecmp(argv[1],"--help") == 0)) {
    cout << "Usage: lms_plot_values PATH [BAUD RATE]" << endl
     << "Ex: lms_plot_values /dev/ttyUSB0 9600" << endl;
    return -1;
  }

正如它所说,它会抛出一个错误,并杀死程序,说要我从命令行输入“lms_plot_values / dev / ttyUSB0 9600”来运行程序,但我不能这样做,我想要在日食中做一切,所以我不想这样做.我试过添加

argv[1] = "/dev/ttyUSB0";
argv[2] = "9600";

但是,由于argc检查,这不行.你知道是否传入“lms_plot_values / dev / ttyUSB0 9600”,为什么会期待或从哪里获取argc值?或者我怎么能认为这些参数是通过的?我不太熟悉C如此工作,我只使用Java.

感谢任何帮助

解决方法

你也可以在eclipse中传递参数.构建项目后,尝试创建运行配置,然后可以传递参数.这是屏幕截图:

相关文章

对象的传值与返回说起函数,就不免要谈谈函数的参数和返回值...
从实现装饰者模式中思考C++指针和引用的选择最近在看...
关于vtordisp知多少?我相信不少人看到这篇文章,多半是来自...
那些陌生的C++关键字学过程序语言的人相信对关键字并...
命令行下的树形打印最近在处理代码分析问题时,需要将代码的...
虚函数与虚继承寻踪封装、继承、多态是面向对象语言的三大特...