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
を取得私は率直に言って、コードをデバッグする方法を知らない。助けてください。
すごいああ、私の信じられないほど愚かでした。それを指摘してくれてありがとう@無償 – Gompu