c++ - 在 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;
}
}
解决方案
推荐阅读
- ios - image upload using POST-API when iOS app is in background
- forms - 如何在 SuiteCRM 中制作注册表单以在 CRM 上存储用户密码
- python - 如何在 python 数据框中将格式为 43004 的字符串转换为日期?
- react-native - 在 ReactNative 中以 Table 格式显示对象数组的值
- python - 如何不接受一个电子邮件地址用于 django 中的多个注册帐户?
- r - 根据另一个不同长度的数据帧中是否存在 NA 过滤一个数据帧
- android - java.lang.IllegalArgumentException:未知 URI:content://downloads/public_downloads/967
- postgresql - 如何将 NULL 值插入 PostgreSQL 表
- arrays - JSON数据并放入数组
- prestashop-1.7 - 将 prestashop 从 localhost 移动到服务器的问题