我正在尝试在C ++中实现hash_multimap。这是代码:
#include <hash_map>
#include<iostream>
#include <string>
#include <hashtable.h>
#include <hash_set>
#include <stdlib.h>
#include <stdio.h>
struct eqstr{
bool operator()(const char *s1,const char* s2)const{
return strcmp(s1,s2)==0;
}
};
typedef hash_multimap<const char*, int, hash<const char*>, eqstr> map_type;
int main() {
return (EXIT_SUCCESS);
}
但这是错误的:
usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/david/NetBeansProjects/hash_multimap'
/usr/bin/make -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/hash_multimap
make[2]: Entering directory `/home/david/NetBeansProjects/hash_multimap'
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/main.o.d
g++ -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/main.o main.cpp
from main.cpp:1:
In file included from /usr/include/c++/4.4/backward/hash_map:60,
/usr/include/c++/4.4/backward/backward_warning.h:28:2: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated.
main.cpp: In member function ‘bool eqstr::operator()(const char*, const char*) const’:
main.cpp:10: error: ‘strcmp’ was not declared in this scope
main.cpp: At global scope:
main.cpp:15: error: expected initializer before ‘<’ token
make[2]: *** [build/Debug/GNU-Linux-x86/main.o] Error 1
make[2]: Leaving directory `/home/david/NetBeansProjects/hash_multimap'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/david/NetBeansProjects/hash_multimap'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
如何解决此问题?
答案 0 :(得分:2)
首先,如果您使用的是strcmp,则需要包含&lt; string.h&gt;。
其次,您可能需要找出hash_multimap的定义位置。它不是C ++ std命名空间的一部分。例如,使用g ++,您可能想尝试:
using namespace __gnu_cxx;
答案 1 :(得分:2)
问题似乎非常简单。
跟踪已弃用的标头,并查找已升级的软件包,库等。否则,请手动编辑代码以更新已弃用的标头。
宣布它。可能包括string.h
稍微不那么明确,但在解决早期问题时可能会更清楚。准确跟踪哪个<
正在创建错误,并开始仔细审核hash_multimap
和hash
的定义
你到底遇到什么问题?
答案 2 :(得分:0)
更改此行:
#include <string>
到此:
#include <string.h>