gpt4 book ai didi

c++ - 仅在 Linux 上出现奇怪的 C++ 未知错误

转载 作者:IT王子 更新时间:2023-10-29 00:34:53 26 4
gpt4 key购买 nike

<分区>

正如标题所说,我在 C++ 中遇到了一个错误,该错误仅发生在 Linux(Ubuntu、C++11)上。现在,为了调试对代码进行了一些修改,因此它应该打印出与“myword”相比的前十个单词。

//Converts String to lower case
string &strToLower(string& s) {
for(char& c: s) {
if(c > 64 && c < 64 + 27) c += 32;
}
return s;
}

//Main Method
int main(int argc, char** args) {
const string libfile = "english-wordlist.txt";
const string filename = "myfile.txt";
const string outfile = "myfile.out";

string myword = "word"; //Word to be compared

//Intended for future use
ifstream f(filename);
vector<string> words;
for(string line; getline(f, line); ) {
for(string& s: split(line)) {
words.push_back(strToLower(s));
}
}
f.close();

//Read the other file
f.open(libfile);
vector<unsigned char> keys;
int ln = 0;
for(string line; ln < 10 && getline(f, line); ln++) {
//Guessing error occurs near this line
cout << "Testing " << line << " against " << myword << endl;
if(strToLower(line) == myword) {
cout << "Found word at " << ln << endl;
}
}
f.close();

cout << endl << "Finished " << endl;
//while(getchar() != 'e'); //Used for Window OS
return 0;
}

但是输出是:

 against word
against word
against word
against wordg
against word
against wordark
against wordarks
against wordolf
against word
against word

Finished

有谁知道为什么会这样?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com