高手进来看一下吧,谢谢
#pragmawarning(disable:4786)#include<iostream>#include<string>#include<map>usingnames...
#pragma warning(disable:4786)
#include <iostream>
#include <string>
#include <map>
using namespace std;
typedef map<int, string, less<int> >INT2STRING;
void main()
{
// 1.Create a map of ints to strings
INT2STRING theMap;
INT2STRING::iterator theIterator;
string theString="";
int index;
//Fill it with the digits 0-9 ,each mapped to its string counterpart
//Note:value_type is a pair for maps……
theMap.insert(INT2STRING::value_type(0,"Zero"));
theMap.insert(INT2STRING::value_type(1,"One"));
theMap.insert(INT2STRING::value_type(2,"Two"));
theMap.insert(INT2STRING::value_type(3,"Three"));
theMap.insert(INT2STRING::value_type(4,"Four"));
theMap.insert(INT2STRING::value_type(5,"Five"));
theMap.insert(INT2STRING::value_type(6,"Six"));
theMap.insert(INT2STRING::value_type(7,"Seven"));
theMap.insert(INT2STRING::value_type(8,"Nine"));
theMap.insert(INT2STRING::value_type(9,"Ten"));
//Read a Number from the user and print it back as words
for(; ;)
{
cout<<"Enter \"q\" to quit,or enter a Number: ";
cin>>theString;
if(theString=="q")
break;
//extract each digit from the string ,find its corresponding
//entry in the map(the word equivalent) and print it
for(index=0;index<theString.length();index++)
{
theIterator=theMap.find(theString[index]-'0');
if(theIterator!=theMap.end())
cout<<(*theIterator).second<<" "; //is 0-9
else
cout<<"[err] ";
}
cout<<endl;
}
}
theIterator=theMap.find(theString[index]-'0');
上面这句话该怎么理解? 展开
#include <iostream>
#include <string>
#include <map>
using namespace std;
typedef map<int, string, less<int> >INT2STRING;
void main()
{
// 1.Create a map of ints to strings
INT2STRING theMap;
INT2STRING::iterator theIterator;
string theString="";
int index;
//Fill it with the digits 0-9 ,each mapped to its string counterpart
//Note:value_type is a pair for maps……
theMap.insert(INT2STRING::value_type(0,"Zero"));
theMap.insert(INT2STRING::value_type(1,"One"));
theMap.insert(INT2STRING::value_type(2,"Two"));
theMap.insert(INT2STRING::value_type(3,"Three"));
theMap.insert(INT2STRING::value_type(4,"Four"));
theMap.insert(INT2STRING::value_type(5,"Five"));
theMap.insert(INT2STRING::value_type(6,"Six"));
theMap.insert(INT2STRING::value_type(7,"Seven"));
theMap.insert(INT2STRING::value_type(8,"Nine"));
theMap.insert(INT2STRING::value_type(9,"Ten"));
//Read a Number from the user and print it back as words
for(; ;)
{
cout<<"Enter \"q\" to quit,or enter a Number: ";
cin>>theString;
if(theString=="q")
break;
//extract each digit from the string ,find its corresponding
//entry in the map(the word equivalent) and print it
for(index=0;index<theString.length();index++)
{
theIterator=theMap.find(theString[index]-'0');
if(theIterator!=theMap.end())
cout<<(*theIterator).second<<" "; //is 0-9
else
cout<<"[err] ";
}
cout<<endl;
}
}
theIterator=theMap.find(theString[index]-'0');
上面这句话该怎么理解? 展开
3个回答
展开全部
1、#pragma警告(使无能力:4786)#include<iostream>#include<线>#include<地图>使用namespace 标准; typedef地图<内部,线,较少<内部>>INT2STRING; 排泄主要() {//1.到线INT2STRING theMap 建立一张ints的地图; INT2STRING: :iterator theIterator; 串theString =""; 内部的索引; //用数字0-9充满它,每一个到它的线极相似的物制订 //笔记:价值 _ 打字一对因为地图 …… theMap.insert(INT2STRING::估价 _ 打字(0,"0")); theMap.insert(INT2STRING::估价 _ 打字(1,"一")); theMap.insert(INT2STRING::估价 _ 打字(2,"两")); theMap.insert(INT2STRING::估价 _ 打字(3,"3")); theMap.insert(INT2STRING::估价 _ 打字(4,"4")); theMap.insert(INT2STRING::估价 _ 打字(5,"5")); theMap.insert(INT2STRING::估价 _ 打字(6,"6")); theMap.ins ert(INT2STRING::估价 _ 打字(7,"7")); theMap.insert(INT2STRING::估价 _ 打字(8,"9")); theMap.insert(INT2STRING::估价 _ 打字(9,"10")); //读那些用户的号码并且作为话向后打印它为(; ; ) {cout<<"\进入"q \"辞职,或者号码": ; cin >>theString; 如果(theString = ="q")打破; //从这根线中抽出每位数字,找到它相应 //在地图(话相等)里的进入和为(索引= 0 打印它; 索引<theString.length(); 索引) {theIterator = theMap.find(theString [索引 ]-' 0 ' ) ; 如果(theIterator!= theMap.end())cout <<(* theIterator).second <<""; //是0-9 其他的cout <<"[犯错误 ]"; }cout <<endl; }}
2、theIterator = theMap.find(theString [索引 ]-' 0 ' ) ;
2、theIterator = theMap.find(theString [索引 ]-' 0 ' ) ;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
theIterator=theMap.find(theString[index]-'0');
表示在theMap中查找theString[index]-'0'对应的项;其中theString[index]表示第index位置上的字符,如果theString为数字字符,那么theString[index]-'0'的含义就是theString[index]字符对应字符'0'的整数偏移值。
表示在theMap中查找theString[index]-'0'对应的项;其中theString[index]表示第index位置上的字符,如果theString为数字字符,那么theString[index]-'0'的含义就是theString[index]字符对应字符'0'的整数偏移值。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1.A=3.8
B=2.8
2.数学书50本
语文书40本
3.(1)10秒后相遇
(2)小明5秒追上小彬
4.15分钟
B=2.8
2.数学书50本
语文书40本
3.(1)10秒后相遇
(2)小明5秒追上小彬
4.15分钟
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询