标签: program-entry-point

如何清理凌乱的主()?

为了使main()(在c ++中)保持尽可能干净/小,你可以选择几个选项,但哪个选项最好?初始化main中的所有变量,在main之外初始化它们作为全局,在.h中全局,在主BUT中初始化它们在其他地方设置值(通过将它们传递给函数).可能还有其他方法但是,将main()保持为干净/清晰/尽可能小的最佳方法是什么?

c++ program-entry-point

0
推荐指数
1
解决办法
221
查看次数

错误:先前在C++中定义的'int main(int,char**)'

我现在正在实现gtest,它给了我一个错误:主要在此定义.

这是utest.cpp

// Bring in my package's API, which is what I'm testing
#include "../src/test.cpp"
// Bring in gtest
#include <gtest/gtest.h>

// Declare a test
TEST(TestSuite, testCase1)
{
     EXPECT_EQ(5,getX(5));
}

// Run all the tests that were declared with TEST()
int main(int argc, char **argv){
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}
Run Code Online (Sandbox Code Playgroud)

这是我正在测试test.cpp的代码

#include "ros/ros.h"
#include "std_msgs/String.h"
#include <Project2Sample/R_ID.h>
#include <geometry_msgs/Twist.h>
#include <nav_msgs/Odometry.h>
#include <sensor_msgs/LaserScan.h>


#include <sstream>
#include "math.h"

int getX(int x)
{
    return x;
}

int main(int argc, char **argv)
{ …
Run Code Online (Sandbox Code Playgroud)

c++ program-entry-point compiler-errors googletest redefinition

0
推荐指数
1
解决办法
6256
查看次数

Java中的String [] args有什么意义?

每当在类中声明main方法时,总是必须执行一个String名为"args" 的数组.重点是什么?除非我生活在摇滚之下,Java中的命令行语言几乎不再使用.当我尝试运行这个...

//this program won't compile
public class SomeClass {
    public static void main(){
        System.out.println("This text will never be displayed :(");
    }
}
Run Code Online (Sandbox Code Playgroud)

输出以红色文本显示:

错误:在SomeClass类中找不到主方法,请将main方法定义为:
    public static void main(String [] args)

我,新手Java程序员,如果有人告诉我为什么需要将该参数输入main方法,我将非常感激.

java convention parameters program-entry-point command-line-arguments

0
推荐指数
1
解决办法
1162
查看次数

String []和String之间的区别

我只是想知道主要方法String[]String主要方法之间的区别

 public static void main(String[] args) {
Run Code Online (Sandbox Code Playgroud)

VS

 public static void main(String args) {
Run Code Online (Sandbox Code Playgroud)

java program-entry-point args

0
推荐指数
1
解决办法
1903
查看次数

Java main()方法无法完全运行 - 从同一应用程序运行客户端和服务器

我一直在研究以下代码:

public class MyStuff {

    public static void main(String[] args)throws IOException {
        //System.out.println("From Test"); 
        ControlGack gack = new ControlGack();
        gack.setVisible(true);
        MainWindow mW = new MainWindow();
        mW.run(null);

        Client c = new Client();
        try {
            c.run(null);
        } catch (IOException e) {
            e.printStackTrace();
        }

        System.out.print("Stupid");
    }
}
Run Code Online (Sandbox Code Playgroud)

MainWindow有一个while循环的程序运行时,只是重复.如何启动Client课程并与课程的其余部分同时运行?

java multithreading program-entry-point client-server runnable

0
推荐指数
1
解决办法
118
查看次数

如何从main调用java中的方法?

import java.util.*;

import java.io.*;

public class Test extends ArrayList
{

    ArrayList<String> list = new ArrayList<String>();

    public static void main(String[] args)
    {
        new Test().add();
        new Test().contains();
    }



    public boolean add(){
        list.add("cat");
        System.out.println(list);
        return true;
    }

    public void contains(){
        if (list.contains("cat")){
            System.out.println("list contains cat");
        }
        else{
            System.out.println("list doesn't contain cat");
        }

    }

}
Run Code Online (Sandbox Code Playgroud)

为什么结果[cat]列表不包含cat?它一直给我[猫]列表不包含猫.第一种方法是正常工作,但为什么不是第二种方法呢?谢谢......我真的很陌生.

java methods program-entry-point call calling-convention

0
推荐指数
1
解决办法
130
查看次数

我应该在main函数内部或外部声明变量吗?

在C++中,建议在主程序内部或其他地方之前声明全局变量?我的意思是,有什么区别

#include <iostream>

int variable;

int main()
{    //my program
     return 0;
}
Run Code Online (Sandbox Code Playgroud)

#include <iostream>

int main()
{
     int variable;
     //my program
     return 0;
}
Run Code Online (Sandbox Code Playgroud)

在哪种情况下我应该使用哪一个?

c++ program-entry-point variable-declaration

0
推荐指数
1
解决办法
2万
查看次数

C++ - int main中的argv []是否总是char*类型(如果使用argv则为char**)?

我知道,因为argc是参数的数量,它可以是一个int.但为什么应该argvchar pointer类型?这是否意味着我无法传递整数参数并argv[1]在数学运算中使用?

编辑:为了使它更清晰,是否可以写出像int* argv[].是否argv已定义为char*无法更改的类型?

c++ program-entry-point char command-line-arguments

0
推荐指数
1
解决办法
85
查看次数

在C中只向main()传递一个参数

我在Linux上用GCC(gcc版本4.8.4(Ubuntu 4.8.4-2ubuntu1~14.04.3))运行了这个程序.它成功编译使用gcc myprog.c和运行没有任何警告或错误.

那么,C中只提供一个参数时,为什么编译器不会给出任何警告或错误main

#include <stdio.h>

int main(int i)
{
    printf("%d\n", i);
}
Run Code Online (Sandbox Code Playgroud)

c gcc program-entry-point

0
推荐指数
1
解决办法
322
查看次数

通过C中的命令行传递标点符号

我有一个程序可以从命令行读取自然语言的句子并对其进行处理。

一些标点符号不被接受:或者我收到一条特定的错误消息(例如,当我使用括号时),或者我收到了>(例如,当我键入时'),好像终端仍在等待什么。

一个快速的解决方法是在引号中包含单个“有问题”的单词,但对我来说似乎不是一个很好的解决方法。

难道没有一种方法可以使命令行准备好将任何字符用作有效输入,而无需让“用户”考虑是否要在引号中包含什么吗?

为了完整起见,这就是我编写命令行内容的方式:int main(int argc , char ** argv){我想这是标准方式。

我正在使用最后一个Ubuntu,不知道这是否相关。

c io bash ubuntu program-entry-point

0
推荐指数
1
解决办法
92
查看次数