看板Programming
标 题[问题]请问VC++ .Net有关Hashtable的问题
发信站梦之大地 (Sun Apr 8 23:34:18 2007)
转信站ptt!ctu-reader!ctu-gate!news.nctu!news2!ccnews.ncku!Dream
大家好:
想请问一下,小弟想写一只程式需要以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