我是一个C++新手.我在这里尝试了我的第一个程序.我的眼睛这个程序是正确的.
#include <iostream>
using namespace std;
class mystruct
{
private:
int m_a;
float m_b;
public:
mystruct(int x, float y)
{
m_a = x;
m_b = y;
}
};
int main()
{
mystruct m = mystruct(5,3.14);
cout << "my structure " << m << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是我得到了很多错误.不知道为什么?
cout.cpp: In function ‘int main()’:
cout.cpp:26:29: error: no match for ‘operator<<’ in ‘std::operator<< [with _Traits = std::char_traits<char>]((* & std::cout), ((const char*)"my structure ")) << m’
cout.cpp:26:29: note: candidates are:
/usr/include/c++/4.6/ostream:110:7: note: std::basic_ostream<_CharT, …Run Code Online (Sandbox Code Playgroud) 我试图了解各种sysconf宏.我编写了一个程序如下.
int main()
{
fprintf(stdout, "No. of clock ticks per sec : %ld\n",sysconf(_SC_CLK_TCK));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我总是得到100的结果.我在一个时钟频率为2.93GHz的CPU上运行它.数字100的确切含义是什么.
我有一个unsigned char指针,其中包含一个结构.现在我想要执行以下操作
unsigned char buffer[24];
//code to fill the buffer with the relevant information.
int len = ntohs((record_t*)buffer->len);
Run Code Online (Sandbox Code Playgroud)
其中record_t结构包含一个名为len的字段.我无法这样做并且收到错误.
error: request for member ‘len’ in something not a structure or union.
Run Code Online (Sandbox Code Playgroud)
然后我尝试了:
int len = ntohs(((record_t*)buffer)->len);
Run Code Online (Sandbox Code Playgroud)
这样才能使操作员优先.那给了我warning:
dereferencing type-punned pointer will break strict-aliasing rules.
然后我宣布
record_t *rec = null;
rec = (record_t*)
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?
我想要一个排序的字典.但之间的项目的顺序mydict和orddict似乎并没有改变.
from collections import OrderedDict
mydict = {'a':1,'b':2,'c':3,'d':4}
orddict = OrderedDict(mydict)
print(mydict,orddict)
# print items in mydict:
print('mydict')
for k,v in mydict.items():
print(k,v)
print('ordereddict')
# print items in ordered dictionary
for k,v in orddict.items():
print(k,v)
# print the dictionary keys
# for key in mydict.keys():
# print(key)
# print the dictionary values
# for value in mydict.values():
# print(value)
Run Code Online (Sandbox Code Playgroud) 我试图在运行12.04的Ubuntu机器上使用mysql创建一个远程数据库.
它有一个root用户,启用了远程登录,没有密码.我已经启动了服务器.
输出
sudo netstat -tap | grep mysql
Run Code Online (Sandbox Code Playgroud)
节目
tcp 0 0 localhost:mysql *:* LISTEN 13246/mysqld
Run Code Online (Sandbox Code Playgroud)
我创建了一个名为nwtopology的数据库(如上所述root还没有密码.)
create database nwtopology
grant all privileges on *.* to root@192.168.129.221
FLUSH PRIVILEGES;
Run Code Online (Sandbox Code Playgroud)
从也运行Ubuntu 12.04的客户端机器我使用python脚本使用sqlalchemy连接到远程mysql数据库.
from pox.core import core
import pox.openflow.libopenflow_01 as of
import re
import datetime
import time
from sqlalchemy import create_engine, ForeignKey
from sqlalchemy import Column, Date, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, backref
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.sql.expression import exists
log …Run Code Online (Sandbox Code Playgroud) 我从这个链接(https://gist.github.com/jiewmeng/3787223)获得了这个程序.我一直在网上搜索,以便更好地理解处理器缓存(L1和L2).我想成为能够编写一个程序,让我能够猜测我的新笔记本电脑上L1和L2缓存的大小.(仅用于学习目的.我知道我可以检查规格.)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define KB 1024
#define MB 1024 * 1024
int main() {
unsigned int steps = 256 * 1024 * 1024;
static int arr[4 * 1024 * 1024];
int lengthMod;
unsigned int i;
double timeTaken;
clock_t start;
int sizes[] = {
1 * KB, 4 * KB, 8 * KB, 16 * KB, 32 * KB, 64 * KB, 128 * KB, 256 * KB,
512 * KB, 1 * MB, 1.5 …Run Code Online (Sandbox Code Playgroud) 我遇到了以下迷宫定义代码:
typedef struct mazeNode {
int hasCheese;
int tag;
struct mazeNode *left;
struct mazeNode *right;
} maze_t;
maze_t maze = {
.tag = 1,
.left = &(maze_t) {
.left = &(maze_t) {
.left = &(maze_t) {},
.right = &(maze_t) {}
},
.right = &(maze_t) {
.right = &(maze_t) {}
}
},
.right = &(maze_t) {
.tag = 8,
.left = &(maze_t) {},
.right = &(maze_t) {
.tag = 10,
.left = &(maze_t) {
.tag = 11,
.left = …Run Code Online (Sandbox Code Playgroud) 我试图运行一个java程序,我得到以下运行时错误.错误如下所示.
Exception in thread "main" java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET
at org.apache.http.impl.client.DefaultHttpClient.setDefaultHttpParams(DefaultHttpClient.java:175)
at org.apache.http.impl.client.DefaultHttpClient.createHttpParams(DefaultHttpClient.java:158)
at org.apache.http.impl.client.AbstractHttpClient.getParams(AbstractHttpClient.java:448)
at org.apache.http.impl.client.AbstractHttpClient.createClientConnectionManager(AbstractHttpClient.java:309)
at org.apache.http.impl.client.AbstractHttpClient.getConnectionManager(AbstractHttpClient.java:466)
at org.apache.http.impl.client.AbstractHttpClient.createHttpContext(AbstractHttpClient.java:286)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:851)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)
at net.floodlightcontroller.core.internal.PacketStreamerClient.registerForPackets(PacketStreamerClient.java:90)
at net.floodlightcontroller.core.internal.PacketStreamerClient.main(PacketStreamerClient.java:51)
Run Code Online (Sandbox Code Playgroud)
现在我添加到类路径的文件如下.
export CLASSPATH=$(JARS=(./lib/*.jar); IFS=:; echo "${JARS[*]}")
export CLASSPATH=$CLASSPATH:~/.m2/repository/org/apache/httpcomponents/httpclient/4.0.1/httpclient-4.0.1.jar
export CLASSPATH=$CLASSPATH:~/.m2/repository/org/apache/httpcomponents/httpcore/4.0.1/httpcore-4.0.1.jar
export CLASSPATH=$CLASSPATH:~/.m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar
export CLASSPAHT=$CLASSPATH:~/ms_thesis/ONOS/httpcore-4.1.jar
#export CLASSPATH=$CLASSPATH:~/ms_thesis/ONOS/lib/httpclient-4.2.jar
export CLASSPATH=$CLASSPATH:~/google-gson-2.2.4/gson-2.2.4.jar
Run Code Online (Sandbox Code Playgroud)
"main"java.lang.NoSuchFieldError:DEF_CONTENT_CHARSET的原因是什么
我下载了,http-core-4.1-alpha因为这是org/apache/http/params/SyncBasicHttpParams class来自findjar.com 的jar
.那个版本的http-core是不可协商的.我如何找到与该版本的http-core兼容的httpclient版本?
我有以下示例程序
#include <stdio.h>
#include <stdlib.h>
#pragma pack(push)
#pragma pack(1)
typedef struct{
char a;
int b;
char c;
}st_a;
#pragma pack(pop)
typedef struct{
char a;
int b;
char c;
}st_b;
int main()
{
printf("size of struct a %zd \n",sizeof(st_a));
printf("size of struct b %zd \n",sizeof(st_b));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
上述计划的输出是
size of struct a 6
size of struct b 12
Run Code Online (Sandbox Code Playgroud)
现在,如果我更改结构声明如下:
#pragma pack(1)
typedef struct{
char a;
int b;
char c;
}st_a;
#pragma unpack()
Run Code Online (Sandbox Code Playgroud)
该计划的输出是
size of struct a 6
size of …Run Code Online (Sandbox Code Playgroud) 我正在编写一些代码,我需要在for循环中使用两个变量.以下代码似乎没问题吗?
它确实给了我预期的结果.
for (loop_1 = offset,loop_2 = (offset + 2); loop_1 >= (offset - 190),loop_2 <= (190 + offset + 2); loop_1--,loop_2++)
{
if ( (*(uint8_t*)(in_payload + loop_1) == get_a1_byte(bitslip)) &&
((*(uint8_t*)(in_payload + loop_2) == get_a2_byte(bitslip)))
)
{
a1_count++;
}
}
Run Code Online (Sandbox Code Playgroud)
但我得到一个编译器警告说:
file.c:499:73:警告:逗号表达式的左侧操作数无效
这是什么意思?
c ×6
python ×2
c++ ×1
c++11 ×1
caching ×1
cpu-cache ×1
dictionary ×1
for-loop ×1
gcc ×1
java ×1
jvm ×1
kernel ×1
linux ×1
mysql ×1
onos ×1
performance ×1
pointers ×1
pragma ×1
python-2.7 ×1
python-3.x ×1
sql ×1
sqlalchemy ×1
struct ×1