小编Kra*_*thi的帖子

将字符串拆分为perl中的名称,值对

假设我有json格式的字符串结果,如下所示.

{ "errorcode": 0, "message": "Done", "login": [ { "session_timeout": "1800", "token": "1370907977", "sessionid": "##F7A7E49F7FCFF35D3F821201CBF2F7CB5937E4AC99BF2AF74B508A1C8B3F", "username": "" } ] }
Run Code Online (Sandbox Code Playgroud)

如何从这个获取哈希表,

hash[errorcode] = 0;  
hash[message] = Done;
Run Code Online (Sandbox Code Playgroud)

PS:不使用任何其他模块并使用简单的字符串函数.

perl

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

未定义的对象错误引用

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

class Part{
public:
    std::string spec;
    Part(std::string str){
        this->spec = str;
    }
    std::string getSpec(){
        return spec;
    }
};

class Car{
public:
    Part getEngine();
    Part getWheels();
    Part getBody();
};


class Benz:public Car{
public:
    Part getEngine(){
        return Part("Benz Engine");
    }   
    Part getWheels(){
        return Part("Benz Wheels");
    }
    Part getBody(){
        return Part("Benz Body");
    }
};

class Audi:public Car{
public:
    Part getEngine(){
        return Part("Audi Engine");
    }   
    Part getWheels(){
        return Part("Audi Wheels");
    }
    Part getBody(){
        return Part("Audi Body");
    }
}; …
Run Code Online (Sandbox Code Playgroud)

c++ oop abstract-class class

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

Poco线程同步问题

下面是示例 Poco 线程程序,以了解互斥锁和线程同步。仍然看到同一程序的不同输出。

#include "Poco/ThreadPool.h"
#include "Poco/Thread.h"
#include "Poco/Runnable.h"
#include "Poco/Mutex.h"
#include <iostream>
#include <unistd.h>
using namespace std;

class HelloRunnable: public Poco::Runnable
{
    public:
        static int a;
        HelloRunnable(){
        }
        HelloRunnable(unsigned long n):_tID(n){
        }
        void run()
        {
            Poco::Mutex::ScopedLock lock(_mutex);
            std::cout << "==>> In Mutex thread " << _tID << endl;
            int i;
            for (i=0;i<50000;i++)
            {
                a = a+1;
            }
            Poco::Mutex::ScopedLock unlock(_mutex);
        }
    private:
        unsigned long _tID;
        Poco::Mutex _mutex;
};
int HelloRunnable::a = 0;
int main(int argc, char** argv)
{
    Poco::Thread thread1("one"), …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading synchronization mutex poco

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

标签 统计

c++ ×2

abstract-class ×1

class ×1

multithreading ×1

mutex ×1

oop ×1

perl ×1

poco ×1

synchronization ×1