在我的程序中,我有一个文本文件被读入一个标记每个单词的数组。我需要这种方式,以便我可以将单词与二叉树中的单词进行比较。问题是......一些重复的单词的格式不同(一个是大写的,一个是小写的),我需要它们这样才能在我的二叉树中找到它们。
所以我的问题是:如何将整个数组更改为小写?
这是我到目前为止所尝试的:
#include <iostream>
#include "Binary_SearchTree.h"
#include "Node.h"
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
const int SIZE = 100;
string myArray[SIZE];
int main() {
// first constructor will be used since it is empty
Binary_SearchTree<string> *tree = new Binary_SearchTree<string>();
string token, lines;
ifstream file("hashtags.txt");
while (getline(file, lines)){
tree -> insertNode(lines);
}
// Convert all strings in myArray to all-lower
myArray = tolower(myArray);
// tokenize tweet into an array to search
ifstream tweet1("exampleTweet.txt");
if(tweet1.is_open())
{
while (getline(tweet1, token)){
for(int i = 0; i < SIZE; ++i)
{
tweet1 >> myArray[i];
}
}
tweet1.close();
}