As the title says, I have an error in C++ that only occurs on Linux (Ubuntu, C++11). Right now, the code is modified a bit for debugging so it's supposed to print out the first ten words in comparison to "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;
}
However the output is:
against word
against word
against word
against wordg
against word
against wordark
against wordarks
against wordolf
against word
against word
Finished
Does anyone know why this occurs?
Aucun commentaire:
Enregistrer un commentaire