Objective-C 关于字典的value的数据类型的输出 10
字典中有一个key的value为2.2,输出的时候是"2.2";字典中还有另外一个key的value为2.0,输出的时候是2.0,没有双引号!为什么?难道不是NSStri...
字典中有一个key的value为2.2,输出的时候是"2.2";字典中还有另外一个key的value为2.0,输出的时候是2.0,没有双引号!为什么?难道不是NSString而是NSUinteger?求大神指教。谢谢!
展开
1个回答
2017-02-20
展开全部
来举个栗子, 不然不清楚具体需要的是什么
#include<iostream>
#include <string>
#include <map>
using namespace std;
class CItem
{
public:
CItem(string& eng,string& ch);
CItem(){m_EngWord = ""; m_ChPra = "";}
string Eng(){return m_EngWord;}
string Ch() {return m_ChPra;}
private:
string m_EngWord;
string m_ChPra;
};
CItem::CItem(string& eng,string& ch)
:
m_EngWord(eng),
m_ChPra(ch)
{
}
class CDictionary
{
public:
CItem FindItem(string& word);
bool AddItem(string& eng,string& ch);
// bool Save2File(string& file);
void PrintAll();
private:
map<string,CItem> m_AllWord;
};
CItem CDictionary::FindItem(string& word)
{
if(m_AllWord.count(word) > 0)
return m_AllWord[word];
else
{
CItem temp;
return temp;
}
}
bool CDictionary::AddItem(string& eng,string& ch)
{
if(eng != "")
{
CItem temp(eng,ch);
m_AllWord[eng] = temp;
return true;
}
return false;
}
// bool CDictionary::Save2File(string& file)
// {
// return true;
// }
void CDictionary::PrintAll()
{
for(map<string,CItem>::iterator it = m_AllWord.begin();it != m_AllWord.end();++it)
{
cout<<"Word:"<<it->second.Eng()<<endl;
cout<<"Parap:"<<it->second.Ch()<<endl;
cout<<"\n";
}
}
int main()
{
CDictionary dic;
string eng = "zhazha";
string ch = "渣渣";
bool re = dic.AddItem(eng,ch);
CItem te = dic.FindItem(eng);
te = dic.FindItem(ch);
dic.PrintAll();
system("pause");
}
是这意思吗看
#include<iostream>
#include <string>
#include <map>
using namespace std;
class CItem
{
public:
CItem(string& eng,string& ch);
CItem(){m_EngWord = ""; m_ChPra = "";}
string Eng(){return m_EngWord;}
string Ch() {return m_ChPra;}
private:
string m_EngWord;
string m_ChPra;
};
CItem::CItem(string& eng,string& ch)
:
m_EngWord(eng),
m_ChPra(ch)
{
}
class CDictionary
{
public:
CItem FindItem(string& word);
bool AddItem(string& eng,string& ch);
// bool Save2File(string& file);
void PrintAll();
private:
map<string,CItem> m_AllWord;
};
CItem CDictionary::FindItem(string& word)
{
if(m_AllWord.count(word) > 0)
return m_AllWord[word];
else
{
CItem temp;
return temp;
}
}
bool CDictionary::AddItem(string& eng,string& ch)
{
if(eng != "")
{
CItem temp(eng,ch);
m_AllWord[eng] = temp;
return true;
}
return false;
}
// bool CDictionary::Save2File(string& file)
// {
// return true;
// }
void CDictionary::PrintAll()
{
for(map<string,CItem>::iterator it = m_AllWord.begin();it != m_AllWord.end();++it)
{
cout<<"Word:"<<it->second.Eng()<<endl;
cout<<"Parap:"<<it->second.Ch()<<endl;
cout<<"\n";
}
}
int main()
{
CDictionary dic;
string eng = "zhazha";
string ch = "渣渣";
bool re = dic.AddItem(eng,ch);
CItem te = dic.FindItem(eng);
te = dic.FindItem(ch);
dic.PrintAll();
system("pause");
}
是这意思吗看
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询