小编ale*_*nis的帖子

什么是sudo bang bang?

让我成为三明治,sudo bang bang

除了这个漫画,我看到有些人写sudo !!.

什么是sudo bang bang?

linux bash terminal sh

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

如何在Eclipse中使用大写文件路径获得$ {include_guard_symbol}?

Eclipse CDT中定义代码模板时,我们可以使用名称${include_guard_symbol}转换为的变量MYFILE_H.

我想更明确一些:SRC_MYFOLDER_MYFILE_H.

我按照Stack Overflow问题的答案中给出的步骤定制了Eclipse CDT的include-guard,但我得到的只是${include_guard_symbol}返回一个空字符串!我还在Stack Overflow上看到了关于将名称空间添加到include guard的其他相关问题,但这不是我正在寻找的.

我使用的是Eclipse版本3.5.2和CDT版本6.0.2.

有没有其他方法可以达到预期的效果?

c++ eclipse eclipse-cdt

9
推荐指数
1
解决办法
3440
查看次数

在宏内部进行Unstringize

在宏内部,我可以使用字符串化运算符#:

#define STRINGIZE(name) #name

cout << STRINGIZE(SomeClass) << endl; // Prints "SomeClass"
Run Code Online (Sandbox Code Playgroud)

是否可以在宏内部执行相反的操作,取消区分?怎么样?

例如:

#define RUN_FUNCTION(name) UNSTRINGIZE(name)();

void myFunction {
  cout << "Hello!" << endl;
}

RUN_FUNCTION("myFunction") // Prints "Hello!"
Run Code Online (Sandbox Code Playgroud)

如果没有,是否有原因?

c++

5
推荐指数
1
解决办法
571
查看次数

优雅地检查用户输入是否有错误

我的程序等待用户输入,并在适当时处理它.我需要检查用户输入以确保它符合某些标准,如果它不符合所有这些标准,它将被拒绝.

伪代码类似于:

if (fulfills_condition_1)
{
    if (fulfills_condition_2)
    {
        if (fulfills_condition_3)
        {
            /*process message*/
        }
        else
            cout << error_message_3; //where error_message_1 is a string detailing error
    }
    else
        cout << error_message_2; //where error_message_2 is a string detailing error
}
else
    cout << error_message_1; //where error_message_3 is a string detailing error
Run Code Online (Sandbox Code Playgroud)

这些条件的数量可能会增加,我想知道是否有一种更简洁的方式来表示使用开关或类似的东西而不是大量的级联if语句.

我知道有可能使用

if (fulfills_condition_1 && fulfills_condition_2 && fulfills_condition_3)
    /*process message*/
else
    error_message; //"this message is not formatted properly"
Run Code Online (Sandbox Code Playgroud)

但这没有第一个那么有用,也没有说明问题出在哪里.

这些条件可以粗略地安排得越来越重要,即检查condition_1比检查更重要condition_3,因此这些if语句确实有效 - 但是这样做有更好的方法吗?

c++ error-handling if-statement

5
推荐指数
1
解决办法
198
查看次数

反转数组

我编写代码来反转整数数组.代码如下所示:

public class ReverseArray {

    public static void main(String[] args) {
        try {
            int[] arr = new int[5];
            arr[0] = 1;
            arr[1] = 2;
            arr[2] = 3;
            arr[3] = 4;
            arr[4] = 5;
            for (int i = 0; i <= arr.length/2; i++)
                int temp = arr[0];
                arr[0] = arr[arr.length - i - 1];
                arr[arr.length - i - 1] = temp;
            }
            System.out.println(arr);

        } catch (Exception e) {
            System.out.println(e);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但它并没有扭转数组......我正在接受输出.

 [I@3bad086a
Run Code Online (Sandbox Code Playgroud)

我没有看到我的逻辑有什么问题.

java

2
推荐指数
2
解决办法
580
查看次数

与联盟和结构混淆

我正在使用这个库在PCL(Point Cloud Library,www.pointclouds.org)上开展一个项目.我可以获得我的Kinect正在查看的内容的3D表示.问题是,我正在使用这个结构:

typedef union
{
    struct
    {
            unsigned char Blue;
            unsigned char Green;
            unsigned char Red;
            unsigned char Alpha;
    };
    float float_value;
    uint32_t long_value;
} RGBValue;
Run Code Online (Sandbox Code Playgroud)

我想用这个结构做的是从每种颜色中获取单个数据并将它们放在浮点数中:

float R = someCloud->points[idx].rgba.Red;   
float G = someCloud->points[idx].rgba.Green;  
float B = someCloud->points[idx].rgba.Blue;  
float A = someCloud->points[idx].rgba.Alpha;  
Run Code Online (Sandbox Code Playgroud)

我得到的错误是这样的:

error C2039: 'Red' : is not a member of 'System::UInt32'*
Run Code Online (Sandbox Code Playgroud)

c++ point-cloud-library

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

合并哈希,不要覆盖里面的列表

在Ruby中,我们可以使用merge函数合并哈希:

1.9.3-p194 :038 > h1 = { "a" => 1, "b" => [1] }
 => {"a"=>1, "b"=>[1]} 
1.9.3-p194 :039 > h2 = { "a" => 2, "b" => [2] }
 => {"a"=>2, "b"=>[2]} 
1.9.3-p194 :040 > h1.merge(h2)
 => {"a"=>2, "b"=>[2]} 
Run Code Online (Sandbox Code Playgroud)

合并会覆盖哈希中的数组,但我希望它能加入它们.

 => {"a"=>2, "b"=>[1, 2]}
Run Code Online (Sandbox Code Playgroud)

是否有红宝石功能或单线程来实现这一目标?

ruby ruby-on-rails

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

javascript代码里面的<script> </ script>标签?

我正在使用我在搜索网络时发现的一个名为Apprise的插件.它迄今为止我所需要的效果很好.但是,我想告诉facebook登录插件,并且我需要遵循以下代码:

<fb:login-button scope='email,publish_stream'>
Login
</fb:login-button>  

<script type='text/javascript' src='http://connect.facebook.net/en_US/all.js'></script>
<script>
window.fbAsyncInit = function() {
    FB.init({
        appId: '123456789',
        cookie: true,
        xfbml: true,
        oauth: true
    });
    FB.Event.subscribe('auth.login', function(response) {
        window.location = '/fb_redirect.php';
    });
    FB.Event.subscribe('auth.logout', function(response) {
        window.location.reload();
    });
    };
    (function() {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol +
        '//connect.facebook.net/en_US/all.js';
        document.getElementById('fb-root').appendChild(e);
    }());
Run Code Online (Sandbox Code Playgroud)

你想要通知的任何东西都可以通过推杆来完成

apprise();
Run Code Online (Sandbox Code Playgroud)

在javascript中.但是,将<script></script>标记放在JS代码(apprise();)中会导致各种混淆,因为它不清楚JS代码的结束位置.

有任何想法吗?

javascript jquery

-2
推荐指数
1
解决办法
195
查看次数