| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 500 人关注过本帖
标题:请高手指点一下这段代码错在什么地方
只看楼主 加入收藏
HY枯叶
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2010-9-20
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
请高手指点一下这段代码错在什么地方
//统计并输出所读入的单词出现的次数
#include<iostream>
#include<string>
#include<map>
using namespace std;

int main()
{
    map<stirng, int> wordCount;
    string word;

    cout << "Enter word for map(ctrl+z end): " << endl;
    while (cin >> word)
        ++wordCount[word];

    cout << "word\t\t" << "times" << endl;
    for(map<string, int>::iterator iter = wordCount.begin();
        iter != wordCount.end(); ++iter)
            cout << (*iter).first << "\t\t"
                 << (*iter).second << endl;
    return 0;
}
在code::blocks下编译时出现以下错误:
G:\源程序\cpp.prime\第十章\习题\10-9.cpp: In function 'int main()':
G:\源程序\cpp.prime\第十章\习题\10-9.cpp:9: error: 'stirng' was not declared in this scope
G:\源程序\cpp.prime\第十章\习题\10-9.cpp:9: error: template argument 1 is invalid
G:\源程序\cpp.prime\第十章\习题\10-9.cpp:9: error: template argument 3 is invalid
G:\源程序\cpp.prime\第十章\习题\10-9.cpp:9: error: template argument 4 is invalid
G:\源程序\cpp.prime\第十章\习题\10-9.cpp:9: error: invalid type in declaration before ';' token
G:\源程序\cpp.prime\第十章\习题\10-9.cpp:15: error: no match for 'operator[]' in 'wordCount[word]'
G:\源程序\cpp.prime\第十章\习题\10-9.cpp:25: error: request for member 'begin' in 'wordCount', which is of non-class type 'int'
G:\源程序\cpp.prime\第十章\习题\10-9.cpp:26: error: request for member 'end' in 'wordCount', which is of non-class type 'int'
搜索更多相关主题的帖子: word 统计 
2011-03-16 23:33
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9008
专家分:53957
注 册:2011-1-18
收藏
得分:10 
'stirng' was not declared in this scope
错误输出中已经描述得很清楚了,我无让用语言描述得更清楚
2011-03-17 08:22
lintaoyn
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:4
帖 子:606
专家分:2499
注 册:2009-4-8
收藏
得分:10 
map<stirng, int> wordCount;
//string你拼写错误(你的编译器没给你指出是哪错么)

迭代的是人,递归的是神。
2011-03-17 12:46
HY枯叶
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2010-9-20
收藏
得分:0 
回复 3楼 lintaoyn
谢谢!  没有仔细看
2011-03-17 18:05
快速回复:请高手指点一下这段代码错在什么地方
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014463 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved