0
Rcpp의 표준 템플릿 라이브러리 (STL)를 사용하여 데이터 구조 및 알고리즘 구현을 배우려는 초보자입니다. (element14 blog에서 촬영)rcpp에서 unordered_map 사용
내가 Rcpp에 구현하려는 해들리의 Advanced R
여기인 C++ 코드에서 힌트를 복용, Rcpp에 unordered_map도 사용하여 매우 기본적인 해시 테이블을 구현하기 위해 노력하고
#include <unordered_map>
#include <string>
#include <iostream>
using namespace std;
int main()
{
unordered_map<string, string> hashtable;
hashtable.emplace("www.element14.com", "184.51.49.225");
cout << "IP Address: " << hashtable["www.element14.com"] << endl;
return 0;
}
동일한 코드
내 Rcpp 버전합니다 (INT 주를 무시하세요, 나는 지금 해시를 int로 이름을 것입니다)
// [[Rcpp::plugins(cpp11)]]
#include <Rcpp.h>
#include <unordered_map>
#include <string>
using namespace Rcpp;
//[[Rcpp::export]]
int hash_test{
std::unordered_map<std::string, std::string> hashtable;
hashtable.emplace("www.element14.com", "184.51.49.225");
Rcout << "IP Address: " << hashtable["www.element14.com"] << endl;
return 0;
}
에
sourceCpp ("./ hash_test.cpp")
내가 (나는 C 아니다 ++ 전문, 그래서 어떤 바보 같은 실수를 무시하십시오) 다음과 같은 오류를 얻을 수
hash_test.cpp:11:46: error: expected primary-expression before ‘hashtable’
std::unordered_map<std::string, std::string> hashtable;
^
hash_test.cpp:11:46: error: expected ‘}’ before ‘hashtable’
hash_test.cpp:11:46: error: expected ‘,’ or ‘;’ before ‘hashtable’
hash_test.cpp:12:1: error: ‘hashtable’ does not name a type
hashtable.emplace("www.element14.com", "184.51.49.225");
^
hash_test.cpp:14:1: error: ‘Rcout’ does not name a type
Rcout << "IP Address: " << hashtable["www.element14.com"] << endl;
^
hash_test.cpp:15:1: error: expected unqualified-id before ‘return’
return 0;
^
hash_test.cpp:16:1: error: expected declaration before ‘}’ token
}
^
make: *** [hash_test.o] Error 1
Error in sourceCpp("./CDM_Open_Source_ME/kohls_model/hash_test.cpp") :
Error 1 occurred building shared library.
In addition: Warning message:
No function found for Rcpp::export attribute at hash_test.cpp:9
를 실행 나는 솔직히 코드를 디버깅하는 방법을 모른다. 도와주세요.
와우 아, 나를 믿을 수 없을만큼 바보였다. @coatless를 지적 해 주셔서 감사합니다. – Gompu