小编yak*_*yak的帖子

如何在CORBA中获取和设置类字段?(处理CORBA对象的序列)

我有这样的事:

User.idl:

#ifndef __USER_IDL__
#define __USER_IDL__

interface Group;

interface User
{
    typedef sequence<Group> Groups;
    Groups getGroups();
    void setGroups(in Groups g);
};

#endif
Run Code Online (Sandbox Code Playgroud)

UserImpl.h和UserImpl.cpp:

class UserImpl : public POA_User
{
    private :
        User::Groups groups;
    public :

        User::Groups* getGroups();
        void setGroups(const ::User::Groups& g);
};

#endif

#include "UserImpl.h"

User::Groups* UserImpl::getGroups()
{
    return &(this->groups);
}

void UserImpl::setGroups(const ::User::Groups& g)
{
    this->groups.length(g.length());
    for(int i=0; i<g.length(); i++)
    {
        this->groups[i] = this->groups[i];
    }
}
Run Code Online (Sandbox Code Playgroud)

和Group.idl:

#ifndef __GROUP_IDL__
#define __GROUP_IDL__

#include "User.idl"

interface Group
{
    typedef sequence<User> Users; …
Run Code Online (Sandbox Code Playgroud)

c++ corba sequence omniorb

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

C++中的线性同余生成器

我写了一个简单的程序(试图实际实现线性同余生成器),但我不太确定它的工作原理应该如何.

我想使用我的生成器从[0,1]生成250个数字.但是,似乎不是随机数,而是我得到相等的值.

如何改进它/我做错了什么?

这是代码:

#include <iostream>
#include <cmath>

static const double A = 0.001342;
static const double C = 0.00025194;
static const double RAND_MAX = 1.0;

double rand()
{
    static double prev = 0;
    prev = A * prev + fmod(C, RAND_MAX);
    return prev;
}

int main(int argc, char **argv)
{
    for(int i=0; i<6; i++)
    std::cout << rand() << "\n";
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

并输出:

0.00025194
0.000252278
0.000252279
0.000252279
0.000252279
0.000252279
Run Code Online (Sandbox Code Playgroud)

然而,切换到int而不是double给出一些不错的结果:

#include <iostream>
#include <cmath>

static …
Run Code Online (Sandbox Code Playgroud)

c++ random generator

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

使用urllib下载HTTPS页面,错误:14077438:SSL例程:SSL23_GET_SERVER_HELLO:tlsv1 alert内部错误

我用最新Kubuntu的Python 2.7.6.我尝试https使用以下代码下载页面:

import urllib2

hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
       'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
       'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
       'Accept-Encoding': 'none',
       'Accept-Language': 'pl-PL,pl;q=0.8',
       'Connection': 'keep-alive'}

req = urllib2.Request(main_page_url, headers=hdr)

try:
    page = urllib2.urlopen(req)
except urllib2.HTTPError, e:
    print e.fp.read()

content = page.read()
print content
Run Code Online (Sandbox Code Playgroud)

但是,我收到这样的错误:

Traceback (most recent call last):
  File "test.py", line 33, in <module>
    page = urllib2.urlopen(req)
  File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 404, …
Run Code Online (Sandbox Code Playgroud)

python ssl python-2.7

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

继承和复制构造函数 - 如何从基类初始化私有字段?

我有2个班,A和B.在A我有3个私人领域.在类中,B我想编写一个复制构造函数,并从类初始化私有字段A.但是,这不起作用:

#include <iostream>
#include <string>
using namespace std;

class A
{
    private:

        string *field1;
        string *field2;
        string *field3;
        double num1;

    public:

        A(string *o, string *n, string *m, double a=0)
        {
            field1 = new string(*o);
            field2 = new string(*n);
            field3 = new string(*m);
            num1 = a;
        }

        A(const A& other) {
            field1 = new string(*other.field1);
            field2 = new string(*other.field2);
            field3 = new string(*other.field3);
            num1 = other.num1;
        }

        void show()
        {
            cout …
Run Code Online (Sandbox Code Playgroud)

c++ inheritance copy-constructor

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

如何连接客户端(在VirtualBox上)和服务器(在localhost上)?我使用CORBA和C++/Java

我有一个简单的'Hello world' C++/Java应用程序CORBA.服务器是写入的C++,客户端在Java.我使用omniORBs omniNames作为名称服务.

我想omniNames在我的localhost (Ubuntu)上运行我的服务器,并在我的localhost Ubuntu上安装的VirtualBox中的Windows XP SP3上运行我的客户端.

(我的意思是:在我的localhost上我安装了Ubuntu操作系统,在Ubuntu中我安装了VirtuaBox和Windows XP SP3'.')

我试过这个:

  1. 我在我的Ubuntu localhost上运行omniNames,: omniNames -start
  2. 我在同一台计算机上运行我的服务器,使用Ubuntu OS运行本地主机: ./server -ORBInitRef NameService=corbaloc::localhost:2809/NameService
  3. 我在网站上检查了我的localhosts ip地址:http://whatismyipaddress.com/并将其写下来,例如:xxxx
  4. 在VirtualBox上打开Windows XP,运行客户端: java client -ORBInitRef NameService=corbaloc::x.x.x.x:2809/NameService

但是有错误:

C:\Temp\java>java client -ORBInitRef NameService=corbaloc:212.106.19.209:2809/Na
meService
pa? 10, 2012 3:51:17 PM com.sun.corba.se.impl.naming.namingutil.CorbalocURL badA
ddress
WARNING: "IOP00110603: (BAD_PARAM) Bad host address in -ORBInitDef"
org.omg.CORBA.BAD_PARAM:   vmcid: SUN  minor code: 603  completed: No
        at com.sun.corba.se.impl.logging.NamingSystemException.insBadAddress(Unk
nown Source)
        at …
Run Code Online (Sandbox Code Playgroud)

c++ java connection virtualbox corba

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

Winsock2,客户端-服务器通信——轮流发送/接收

我想编写一个客户端/服务器应用程序,客户端和服务器可以在其中交换消息。

Client site communication:

send
recv
send 
recv

Server site communication:

recv
send
recv
send
Run Code Online (Sandbox Code Playgroud)

但是,我有一个问题,因为只有一条消息是发送/接收。之后,套接字关闭,不再发送进一步的消息。出了什么问题,如何解决这个问题?谢谢你。

服务器代码:

#undef UNICODE

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>
#pragma comment (lib, "Ws2_32.lib")
#define DEFAULT_PORT "27501"
#define SIZE 1024

int SendAllToClient(SOCKET ClientSocket, char *buffer)
{
    int iSendResult;


    int total = 0, len = 1024;
    int bytesleft = 1024;

    while( total < len )
    {
        iSendResult = send( ClientSocket, buffer, 1024, NULL);

        if (iSendResult == SOCKET_ERROR)
        {
            printf("send failed …
Run Code Online (Sandbox Code Playgroud)

c++ winsock send recv winsock2

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

使用 openssl 进行 MD4 哈希,将结果保存到字符数组中

我用 C 语言用 openssl 写了一个简单的例子。我想从我的消息中计算 MD4 哈希值,但我想将结果保存到一个字符数组中。这是我的带有注释的代码,可以帮助您了解我想要实现的目标:

#include <string.h>
#include <openssl/md4.h>
#include <stdio.h>

int main()
{
    unsigned char digest[MD4_DIGEST_LENGTH];
    char string[] = "hello world";

    // run md4 for my msg
    MD4((unsigned char*)&string, strlen(string), (unsigned char*)&digest);

    // save md4 result into char array - doesnt work
    char test[MD4_DIGEST_LENGTH];
    sprintf(test, "%02x", (unsigned int)digest);
    for(int i = 0; i < MD4_DIGEST_LENGTH; i++)
        printf("%02x", test[i]);
    printf("\n\n");

    // print out md4 result - works, but its not intochar array as I wanted it to be …
Run Code Online (Sandbox Code Playgroud)

c openssl

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

警告:未知转义序列:'\ 040'[默认启用]

我正在用C编写一个简单的应用程序,我想在BSD许可下发布它。该应用程序的一部分负责将有关该程序的信息输出到其用户。但是,我在打印许可证文本时遇到问题。这是示例:

#include <stdio.h>
#include <stdlib.h>

void show_license(void)
{
    const char *license = "\n\
 Copyright (c) 2012 \n\
 All rights reserved.\n\
 \"Redistribution and use in source and binary forms, with or without\n\
 modification, are permitted provided that the following conditions are\n\
 met:\n\
\n\
   * Redistributions of source code must retain the above copyright\n\
     notice, this list of conditions and the following disclaimer.\n\
   * Redistributions in binary form must reproduce the above copyright\n\
     notice, this list of conditions and the following disclaimer …
Run Code Online (Sandbox Code Playgroud)

c string warnings

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

如何在Python中编码和解码百分比编码(URL编码)字符串?

我写了一个简单的应用程序,从wiki页面下载文章.当我搜索例如第一个名字时Lech,我的代码返回的字符串代替Lech_Kaczy%C5%84ski或Lech_Pozna%C5%84代替Lech_Kaczy?ski和Lech_Pozna?.

如何将这些字符解码为普通的抛光字母?我尝试使用: urllib.unquote(text)但后来得到了Lech_Kaczy\xc5\x84ski,Lech_Pozna\xc5\x84而不是Lech_Kaczy?ski和Lech_Pozna?.

我的代码中有:

# -*- coding: utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
Run Code Online (Sandbox Code Playgroud)

但结果是一样的(它根本不起作用).

python encoding

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

QString arg 中的参数不超过 9 个?怎么处理呢?

我写了一个超过 9 个参数的长 QString,我只是这样使用它:

QString html = QObject::tr(
                "%1 %2 %3 %4 %5 %6 %7 %8 %9 %10 ...").arg(a, b, c, d, e, f, g, h, i, j);
Run Code Online (Sandbox Code Playgroud)

但是 QtCreator 产生错误,参数不能超过 9 个...我阅读了文档: http: //doc.qt.io/qt-5/qstring.html,其中有一个arg函数定义:

QString arg(const QString & a1, const QString & a2, const QString & a3, const QString & a4, const QString & a5, const QString & a6, const QString & a7, const QString & a8, const QString & a9) const

所以看来这就是问题所在。有什么优雅的方法可以处理这个问题,或者我只能连接 2 个字符串?

c++ qstring qt

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