注册 登录
编程论坛 C++教室

请高手指点一下这段代码错在什么地方

HY枯叶 发布于 2011-03-16 23:33, 500 次点击
//统计并输出所读入的单词出现的次数
#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'
3 回复
#2
rjsp2011-03-17 08:22
'stirng' was not declared in this scope
错误输出中已经描述得很清楚了,我无让用语言描述得更清楚
#3
lintaoyn2011-03-17 12:46
map<stirng, int> wordCount;
//string你拼写错误(你的编译器没给你指出是哪错么)
#4
HY枯叶2011-03-17 18:05
回复 3楼 lintaoyn
谢谢!  没有仔细看
1