You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
int main() {
std::string file1, file2;
std::cout << "Enter the name of the first file: ";
std::cin >> file1;
std::cout << "Enter the name of the second file: ";
std::cin >> file2;
std::ifstream in1(file1);
std::ifstream in2(file2);
if (!in1 || !in2) {
std::cout << "Error opening one of the files.\n";
return 1;
}
int word_count1 = 0, word_count2 = 0;
std::string word1, word2;
while (in1 >> word1 && in2 >> word2) {
++word_count1;
++word_count2;
// Ignore case when comparing the words
std::transform(word1.begin(), word1.end(), word1.begin(), ::tolower);
std::transform(word2.begin(), word2.end(), word2.begin(), ::tolower);
if (word1 != word2) {
break;
}
}
std::cout << "Number of words in first file: " << word_count1 << '\n';
std::cout << "Number of words in second file: " << word_count2 << '\n';
if (word_count1 == word_count2) {
std::cout << "Files are 100% similar.\n";
} else {
std::cout << "Files are not similar.\n";
}
return 0;
}
The text was updated successfully, but these errors were encountered:
#include
#include
#include
#include
int main() {
std::string file1, file2;
std::cout << "Enter the name of the first file: ";
std::cin >> file1;
std::cout << "Enter the name of the second file: ";
std::cin >> file2;
std::ifstream in1(file1);
std::ifstream in2(file2);
if (!in1 || !in2) {
std::cout << "Error opening one of the files.\n";
return 1;
}
int word_count1 = 0, word_count2 = 0;
std::string word1, word2;
while (in1 >> word1 && in2 >> word2) {
++word_count1;
++word_count2;
// Ignore case when comparing the words
std::transform(word1.begin(), word1.end(), word1.begin(), ::tolower);
std::transform(word2.begin(), word2.end(), word2.begin(), ::tolower);
if (word1 != word2) {
break;
}
}
std::cout << "Number of words in first file: " << word_count1 << '\n';
std::cout << "Number of words in second file: " << word_count2 << '\n';
if (word_count1 == word_count2) {
std::cout << "Files are 100% similar.\n";
} else {
std::cout << "Files are not similar.\n";
}
return 0;
}
The text was updated successfully, but these errors were encountered: