我有以下代码:
set<Key> test;
test.insert(key1);
test.insert(key2);
iter1 = test.find(key1);
iter2 = test.find(key2);
test.erase(iter1);
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果删除了key1,我现在可以使用iter2来引用test2中的key2吗?
谢谢
也许是一个重复的问题,尽管我试图找出现有问题的答案但却失败了.
我用命令在服务器上创建了一个git repo:
mkdir gitrepo
cd gitrepo
git init
Run Code Online (Sandbox Code Playgroud)
然后从另一台机器我试图将文件推送到此repo但失败了.
git init
git clone user@server:~/gitrepo/.git
cd gitrepo
touch test
git add test
git commit -a
Run Code Online (Sandbox Code Playgroud)
现在使用,不会发生错误.当我尝试将更改推送到服务器时,会发生以下错误:
>git push
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'user@server:~/gitrepo/.git'
Run Code Online (Sandbox Code Playgroud)
有没有人遇到过这个问题?
我找到了一个博客,很好地解释了非裸机和裸机的区别.http://www.bitflop.com/document/111 遇到同样问题的人可以参考这个.
我想写一个通用的Pair类,它有两个成员:key和value.这个类的唯一要求是key和value都应该实现Comparable接口,否则Pair类不会接受它们作为类型参数.
首先,我这样编码:
public class Pair<T1 extends Comparable, T2 extends Comparable>
Run Code Online (Sandbox Code Playgroud)
但是JDK 1.6编译器会生成关于此的警告:
Comparable is a raw type. References to generic type Comparable<T> should be parameterized
Run Code Online (Sandbox Code Playgroud)
然后我尝试添加类型参数,代码现在看起来像这样:
public class Pair<T1 extends Comparable<? extends Object>,
T2 extends Comparable<? extends Object>>
Run Code Online (Sandbox Code Playgroud)
现在一切顺利,直到我尝试为Pair生成Comparator.(以下代码在Pair类中)
public final Comparator<Pair<T1, T2>> KEY_COMPARATOR = new Comparator<Pair<T1, T2>>() {
public int compare(Pair<T1, T2> first, Pair<T1, T2> second) {
*first.getKey().compareTo(second.getKey());*
return 0;
}
};
Run Code Online (Sandbox Code Playgroud)
该代码first.getKey().compareTo(second.getKey());将生成错误说:
The method compareTo(capture#1-of ? extends Object) in the type Comparable<capture#1-of ? extends Object> is …Run Code Online (Sandbox Code Playgroud) 使用inotify时遇到一些问题.我使用inotify来监视文件的变化.这是我的代码:
int fd = inotify_init();
int wd = inotify_add_watch(fd, "/root/temp", IN_ALL_EVENTS);
int bufSize = 1000;
char *buf = new char[bufSize];
memset(buf, 0, sizeof(buf));
int nBytes = read(fd, buf, bufSize - 1);
cout << nBytes << " bytes read" << endl;
inotify_event *eventPtr = (inotify_event *)buf;
int offset = 0;
while (offset < nBytes)
{
cout << eventPtr->mask << endl;
offset += sizeof(inotify_event) + eventPtr->len;
eventPtr = (inotify_event *)(buf + offset);
}
delete []buf;
Run Code Online (Sandbox Code Playgroud)
如果我删除"/ root/temp"并重新创建这样的文件,则inotify不会监视此文件的任何更改,这是怎么回事?谢谢.
程
任何人都知道如何在postgresql中将search_path恢复为默认值?我更改了它的值,但现在我想再次使用默认值.任何帮助表示赞赏.
程
我使用读取函数从套接字读取数据,但是当数据超过4k时,读取函数只读取部分数据,例如,小于4k.这是关键代码:
mSockFD = socket(AF_INET, SOCK_STREAM, 0);
if (connect(mSockFD, (const sockaddr*)(&mSockAdd), sizeof(mSockAdd)) < 0)
{
cerr << "Error connecting in Crawl" << endl;
perror("");
return false;
}
n = write(mSockFD, httpReq.c_str(), httpReq.length());
bzero(mBuffer, BUFSIZE);
n = read(mSockFD, mBuffer, BUFSIZE);
Run Code Online (Sandbox Code Playgroud)
注意比BUFSIZE远大于4k.当数据只有几百个字节时,读取功能按预期工作.
可能重复:
Java中的序列化版本uid
我们知道Java序列化机制会忽略静态字段.如果是这样,那么解串器如何知道序列化器的serialVersionUID.serialVersionUID始终是要序列化的类的静态字段.谢谢您的帮助.
程
c++ ×3
java ×2
comparable ×1
comparator ×1
erase ×1
generics ×1
git ×1
git-push ×1
inotify ×1
postgresql ×1
set ×1
sockets ×1
tcp ×1