首页 > 解决方案 > 在 Visual Studio C++ 中扫描单引号字符串时 EOL

问题描述

因此,起初在编写代码时,我使用了一个大约 100 字的小文件。当我认为我终于设法将一些代码组合在一起并解决了所有问题时,我尝试放入一个大约 450,000 字的更大文件。

它使我的电脑崩溃了。

现在,当我尝试编译代码时,它给了我“ EOL while scanning single-quoted string”,还有

"Unexpected PDB error; FORMAT (11) 'C:\Users\....\...."

我是编码新手,不知道这两个是什么意思,请帮忙!

该代码应该逐字读取文件,根据每个字母的值计算其分数,然后放入一个元组,然后我尝试将元组放入一个向量并将元组元素打印到控制台。

这是我的代码:

#include <iostream>
#include <fstream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

bool checkIfLowercase(string word) {

    for (int i = 0; i < word.length(); i++) {
        if (!islower(word[i])) {
            return false;
        }
    }
    return true;
}

int simpleScore(string word) {
    int wordScore=0;
    for (int i = 0; i < word.length(); i++) {
        string letter(1, word[i]);

        if (letter == "a")
            wordScore = wordScore + 1;
        if (letter == "e")
            wordScore = wordScore + 1;
        if (letter == "i")
            wordScore = wordScore + 1;
        if (letter == "o")
            wordScore = wordScore + 1;
        if (letter == "u")
            wordScore = wordScore + 1;
        if (letter == "l")
            wordScore = wordScore + 1;
        if (letter == "n")
            wordScore = wordScore + 1;
        if (letter == "s")
            wordScore = wordScore + 1;
        if (letter == "t")
            wordScore = wordScore + 1;
        if (letter == "r")
            wordScore = wordScore + 1;
        if (letter == "d")
            wordScore = wordScore + 2;
        if (letter == "g")
            wordScore = wordScore + 2;
        if (letter == "b")
            wordScore = wordScore + 3;
        if (letter == "c")
            wordScore = wordScore + 3;
        if (letter == "m")
            wordScore = wordScore + 3;
        if (letter == "p")
            wordScore = wordScore + 3;
        if (letter == "f")
            wordScore = wordScore + 4;
        if (letter == "h")
            wordScore = wordScore + 4;
        if (letter == "v")
            wordScore = wordScore + 4;
        if (letter == "w")
            wordScore = wordScore + 4;
        if (letter == "y")
            wordScore = wordScore + 4;
        if (letter == "k")
            wordScore = wordScore + 5;
        if (letter == "j")
            wordScore = wordScore + 8;
        if (letter == "x")
            wordScore = wordScore + 8;
        if (letter == "q")
            wordScore = wordScore + 10;
        if (letter == "z")
            wordScore = wordScore + 10;

        else {
            wordScore = wordScore + 0;
        }

    }
    return wordScore;
}

int main()
{
    ifstream fileWithEverything("test1.txt");

    string wordFromFile;
    int amountOfWords = 0;
    int x;
    vector<tuple<string, int>> vectorWithTuples;

    while (getline(fileWithEverything, wordFromFile)) {
        if (checkIfLowercase(wordFromFile) == true) {

            amountOfWords++;

            x = simpleScore(wordFromFile);

            vectorWithTuples.push_back(make_tuple(wordFromFile, x));

        }

    }
    for (int i = 0; i < wordFromFile.length(); i++) {
        cout << get<0>(vectorWithTuples[i]) << " ";
        cout << get<1>(vectorWithTuples[i]) << endl;


        cout << "Amount of words is: " << amountOfWords << endl;
    }
}

标签: c++

解决方案


推荐阅读