0

and i get error with
error C2451: conditional expression of type 'std::basic_string<_Elem,_Traits,_Ax>' is illegal

void system1::search() {
    cout<<"Enter ID to be Searched: ";
    int data_search;
    cin>>data_search;
     nodetype *current = head;
    while(current != NULL) {
        if(current->ID == data_search) {
                cout<<"\n----Linked List Linear Search Result----\n";
                cout<<"ID: "<< current->ID <<endl;
                cout<<"Name: "<< current->NAME <<endl;
                break;
        }
        else
            current = current->link;
    }


}
3
Contributors
2
Replies
20
Views
2 Years
Discussion Span
Last Post by Maritimo
0

I would suspect, that if ID is a string, that this,if(current->ID == data_search), is trying to compare an int and a string, which are 2 different types. You'll have to change/convert one or the other to the other type.

Edited by tinstaafl

0

data_search is an integer. But is current->ID also an integer?
It seems that current->ID is a string. Probably you can use std::stoi(current->ID) to solve the problem.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.