I'm new at programming and I can't figure this out. Can anyone please help?

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

bool nocase_compare (char c1, char c2)
{
    return toupper(c1) == toupper(c2);
}   

int main( int argc, char* argv[] ) 
{

    ifstream infile; 
    string filename;

    do
    {
        cout << "File name? ";
        cin >> filename;
        infile.open(filename.c_str());
            if (!infile)
            { 
                cerr << "Cannot open file: " << filename << "\n" << endl;
                return 0;
            }

    } while (!infile);


    string line;
    string search;
    int counter = 0;
    size_t found=' ';

    cout << "Search string? ";
    cin >>search;

    string::iterator pos;
    pos = search (line.begin(),line.end(),
        search.begin(),
        search.end(),
        [COLOR="red"]nocase_compare);[/COLOR]  [COLOR="red"]<===Error[/COLOR]

    if (pos == line.end())
    {
        cout <<"not found";
    } 

    else
    {
        cout<<"found";
    }


    infile.close();
    system("pause");
    return 0;
}


error C2064: term does not evaluate to a function taking 5 arguments

1. you should #include<algorithm>

2. you create 'string line;' but then never assign anything to it..

3. so when you call search(line.begin(), line.end(), search.begin(), search.end(), nocase_compare), arguments #1 and #2 will return iterators to a string of nothing.


for more information: http://www.cplusplus.com/reference/algorithm/search/

the search function takes in 4 arguments not five.

What you want is something like this:

//returns true if source contains target with case ignored
bool no_case_compare(const string& source, const string& target){
 string srcCpy(source.size(),0);
 string targetCpy(target.size(),0);
 std::transform(source.begin(),source.end(),srcCpy.begin(),tolower);
 std::transform(target.begin(),target.end(),targetCpy.begin(),tolower);
 return srcCpy.find(targetCpy) != string::npos;
}

According to this documentation:

http://www.cplusplus.com/reference/algorithm/search/

The search() function is overloaded to provide 2 variations of the function to the user, depending on program needs; the first version takes 4 args, the second takes 5.

Thanks for the correction.

thanks a lot guys. appreciate the help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.