請教有關VC++ 2005的Hashtable一問

看板Programming作者時間18年前 (2007/04/09 02:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
大家好: 想請問一下,小弟想寫一隻程式需要以Hashtable做index該怎麼做呢? 要進行index的東西為char msg[] = "aaaa"; (類似這個東西),但是msdn在Hashtable 上用Add加入資料是用Hashtable->("S1", "S2"),但今日我要放的東西不是這麼簡單, 型態轉換上又一直出問題,不知有沒有高手可以救一下? Please... 以下是我的Source Code // 76451.cpp : 定義主控台應用程式的進入點。 // #include "stdafx.h" #include "iostream" #include "atlstr.h" #include "string.h" using namespace std; using namespace System; using namespace System::Collections; int _tmain(int argc, _TCHAR* argv[]) { Hashtable^ table1 = gcnew Hashtable; char* u1 = "aaa"; char* u2 = new char[4]; for(int i = 0; i < 3; i++) u2[i] = 'b'; u2[3] = '\0'; table1->Add(*u1, NULL); table1->Add(*u2, NULL); IEnumerator^ myEnum = table1->GetEnumerator(); while ( myEnum->MoveNext() ) { DictionaryEntry de = *safe_cast<DictionaryEntry ^>(myEnum->Current); Console::WriteLine( "\t{0}:\t{1}", de.Key, de.Value ); } delete table1; return 0; } -- ︵︵ █▔◣ █▔█ █▔▔ █▔█ █▆▉ █ █▔█ █◣█ █▔ █◣︵︵ █ █ █▁◤ █▁▁ █▁█ ▉▉▉ █ █▁█ █◥█ █ █ 夢之大地 逼逼ㄟ四 █▁◤ █ █ █▁▁ █ █ ▉▉▉ █▁ █ █ █ █ █▁◤ ※ Origin: <bbs.ccns.ncku.edu.tw> ◆ From: 220.229.173.14 ※ Modify: 220.229.173.14 Sun Apr 8 23:32:47 2007 ※ Modify: 220.229.173.14 Sun Apr 8 23:33:12 2007
文章代碼(AID): #166ItW00 (Programming)
文章代碼(AID): #166ItW00 (Programming)