小编Zhe*_*Hao的帖子

何时使用虚拟析构函数?

我对大多数OO理论有了深刻的理解,但让我困惑的一件事是虚拟析构函数.

我认为无论什么以及链中的每个对象,析构函数总是会被调用.

你什么时候打算让它们成为虚拟的?为什么?

c++ polymorphism shared-ptr virtual-destructor

1420
推荐指数
13
解决办法
66万
查看次数

Java如何在switch语句下打破while循环?

我有一个功课来实现一个简单的测试应用程序,下面是我目前的代码:

import java.util.*;

public class Test{

private static int typing;

public static void main(String argv[]){
    Scanner sc = new Scanner(System.in);
    System.out.println("Testing starts");
    while(sc.hasNextInt()){
        typing = sc.nextInt();
        switch(typing){
            case 0:
              break; //Here I want to break the while loop
            case 1:
              System.out.println("You choosed 1");
              break;
            case 2:
              System.out.println("You choosed 2");
              break;
            default:
              System.out.println("No such choice");
        }
    }
      System.out.println("Test is done");
    }
}
Run Code Online (Sandbox Code Playgroud)

我现在要做的是,当0按下时,表示用户想要退出测试,然后我打破while loop并打印Test is done,但它不能那样工作,我知道原因可能是"break"打破了switch,我怎么能让它打破while loop呢?

java break while-loop

54
推荐指数
3
解决办法
4万
查看次数

Java,如何删除ArrayList中的Integer项

假设我有这样一个ArrayList:

ArrayList<Integer> list = new ArrayList<Integer>();
Run Code Online (Sandbox Code Playgroud)

添加操作后:

list.add(2);
list.add(3);
list.add(5);
list.add(7);
Run Code Online (Sandbox Code Playgroud)

number 2如果我这样做,我想删除

list.remove(2);
Run Code Online (Sandbox Code Playgroud)

然后number 5将被删除,我怎么能删除number 2?并且假设我不知道索引number 2.

java

47
推荐指数
5
解决办法
4万
查看次数

如何使用s_client将字符串发送到服务器

如何使用s_clientopenssl发送短string到服务器?

我已经阅读了s_client手册,但没有找到任何可用的标志.

或者还有其他方法可以实现这一目标吗?

linux openssl

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

Facebook照片的Android Multipart/form-data编码

用于将照片上传到Facebook相册的新Facebook Android SDK就像这样的链接:

Bundle params = new Bundle();
params.putString("source", "{image-data}");
/* make the API call */
new Request(
session,
"/me/photos",
params,
HttpMethod.POST,
new Request.Callback() {
    public void onCompleted(Response response) {
        /* handle the result */
    }
 }
).executeAsync();
Run Code Online (Sandbox Code Playgroud)

令我困惑的是{image-data},它说照片应该被编码为multipart/form-data,但从params.putString("source", "{image-data}")我们可以看到第二个参数putString()应该是a String,我如何编码图像文件multipart/form-data并获得String格式的返回值?像这样:

public String getImageFormData(File image){
   String imageValue;
    ...

    return imageValue;
}
Run Code Online (Sandbox Code Playgroud)

或者我理解错了,我现在的问题是我有图像文件,如何使用上面的代码将图像成功上传到Facebook?

android facebook

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

C++,错误:'__locale_t'尚未声明

我是新的C++,我得到了error: '__locale_t' has not been declared我一些包含头文件,比如#include "ruby.h",#include <string.h>等等,但有一个为没有问题的#include <stdio.h>,我使用的Eclipse在Linux下,详细的错误的#include "ruby.h"#include <string.h>是:

/usr/include/string.h:548: error: '__locale_t' has not been declared
/usr/include/string.h:549: error: nonnull argument references non-pointer operand (argument 1, operand 3)
/usr/include/string.h:552: error: '__locale_t' has not been declared
/usr/include/string.h:553: error: nonnull argument references non-pointer operand (argument 1, operand 4)
Run Code Online (Sandbox Code Playgroud)

包含的顺序是:

#include "Abc.h"

#include <string.h>
#include "ruby.h"
#include <stdio.h>
Run Code Online (Sandbox Code Playgroud)

Abc班级名称在哪里.

这是Abc类,没有添加除了include:

#include "Abc.h"
#include <stdio.h>
#include …
Run Code Online (Sandbox Code Playgroud)

c c++ eclipse

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

strcmp在C中返回意外值

我是C的新手,我的代码行看起来像这样:

char user[16];
fgets(user,16,stdin);
Run Code Online (Sandbox Code Playgroud)

我在键盘上键入"zeyang",我还有另一个代码:

char pwname[1000];
pwname="zeyang";
Run Code Online (Sandbox Code Playgroud)

然后我strcmp用来比较用户和pwname:

strcmp(user, pwname);
Run Code Online (Sandbox Code Playgroud)

返回值是一个负数,我希望它是0,因为它们都是"zeyang".为什么不是0?

c

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

c ++ main函数,如果命令行参数包含*,则argc值很奇怪

一个非常简单的C++代码,如下所示:

int main(int argc, char **argv){
    std::cout << "argc: " << argc << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

编译 g++ -o hello hello.cpp

  • 运行时./hello u,输出是argc: 2;
  • 运行时./hello u +,输出是argc: 3;
  • 当运行时./hello u *,输出是argc: 26,为什么26

c++ argc

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