繁体   English   中英

C ++ NetBeans中的“未知解析器错误”

[英]“unkown parser error” in c++ netbeans

预先抱歉,我发布了一张图片,但是我还没有回复:(第1行的错误说“未知解析器错误”重复了四行,并且从ReadFile类行开始,几乎每一行都有一条错误说我通过右键单击项目下的“标题”并添加包含它们的文件夹,或者通过右键单击项目名称本身并在其中添加文件夹,从文件夹中包含了所有自定义头文件。是否包含标题的私人摘要。有人有什么想法吗?这是斯坦福大学的免费讲座集,您必须下载并安装其自定义标题..讲师使用的是Visual c ++,但这不应该。是说我不能对Netbeans使用文件,对不对。

#include "genlib.h"
#include <iostream>
#include <fstream>
#include "map.h"
#include "random.h"
#include "set.h"
using namespace std;

void ReadFile(ifstream &in, Map<int> &m)
{
    while (true) {
        string word;
        in >> word;
        if (in.fail()) break;
        if (m.containsKey(word)) 
            m[word]++;
        else
            m[word] = 1;
    }
    Map<int>::Iterator itr = m.iterator();
    string max;
    int maxCount = 0;
    while (itr.hasNext()) {
        string key = itr.next();
        if (m[key] > maxCount) {
            max = key;
            maxCount = m[key];
        }
    }
    cout << "Max is " << max << " = " << maxCount << endl;
}

void TestRandom()
{
    Set<int> seen;
    while (true) {
        int num = RandomInteger(1, 100);
        if (seen.contains(num)) break;
        seen.add(num);
    }
    Set<int>::Iterator itr = seen.iterator();
    while (itr.hasNext()) 
        cout << itr.next() << endl;
}

int main()
{
    ifstream in("burgh.txt");
    Map<int> counts;
    ReadFile(in, counts);
    Randomize();
    TestRandom();
    return 0;
}

在您的ReadFile函数中(在多个位置),您尝试使用字符串作为以整数作为键的Map的键。

string word;
in >> word;
if (in.fail()) break;
if (m.containsKey(word)) 
    m[word]++;

为了正确执行此操作,您将需要将字符串输入解析为整数。 这可以通过stoi函数或类似功能实现。

string word;
in >> word;
int iKey = stoi(word, nullptr);
if (in.fail()) break;
if (m.containsKey(iKey)) 
    m[iKey]++;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM