I'm trying to convert a string that I'm reading from a file to lowercase and hold the lowercase string in a separate string for comparison, but I want to keep the original string around for presentation, but I'm having some trouble:
ifstream file;
string name,
lnStr,
searchStr,
lowerStr;
int lineNum = 0;
int strCount;
while(getline(file, lnStr))
{
lowerStr = lnStr;
for(int i = 0; lowerStr[i] != '\0'; i++){
lowerStr[i] = tolower(lowerStr[i]);
}
if(lowerStr.find(searchStr, 0) < lnStr.npos)
{
cout << setw(5) << ++lineNum << ":" << lnStr << endl;
strCount++;
}
}
apparently I can't use sub[i] on strings, but it seems too much to hold it all in an array. Am I doing this the most efficiently? How can I get my lowercase string and original string separate?