假设我有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:不使用任何其他模块并使用简单的字符串函数.
#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) 下面是示例 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)