A intelligent library database

Hi,
I am using Xcode and i wanted to build a intelligent library database management system. I am a beginner.
I want the user to enter what he wants to do...
1) to add a book or
2) to add a new student or
3) to loan a book or... etc

I want the user to enter any string that comes to his mind and then i want to proceed on basis of that strings.
In this code i have written all the possible strings the user "could" enter.

I know i would have instead used a switch condition and asked the user to enter 1,2 or 3.. as per his choice.
But i really want to build this thing.

Is there any reason i am getting this error?
I am using Xcode(on a mac).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  void adminmenu()
{
sleep(2);
    cout << "What would you like to do? " << endl;
    
    string input;
    getline(cin,input);
    
    
    if (input == "Add a book" || input == "add a book" || input == "I would like to add a book" || input == "i would like to add a book" || input == "I want to add a book" || input == "i want to add a book" || input = "I just want to add a book" || input =="i just want to add a book" || input == "add book" || input == "Add Book" || input == " Add book" || input == "addbook" || input == "ADDBOOK"    )
    {
        cout << "Processing input..." << endl;
        sleep(2);
        
        
        
        
    }
    
    
}


I am getting this error:
Invalid operands to binary expression ( ‘bool’ and ‘strings’ ( aka ‘basic_string<char,char_traits<char>,allocator<char> >’))
Use strfind() to find a word "add" an "book" if both of it is found in string then you can start proessing
Wow! thank you so much.
I need to know how the function is used. Just gimme a example.
I searched on google..But can't find a lot that i can understand.
Thanks.
1
2
3
std::size_t pos=input("add");
if(pos!=std::npos)
  cout<<"you found iit";
As for the compiler error, in the condition for the if statement, in one of the OR conditions you have a typo and used assignment instead of equality comparison.

Change:

input = "I just want to add a book"

to:

input == "I just want to add a book"
@Alrededor:
Thanks for the help.

@LendraDwi:
Can u explain what the code does? I am a beginner.
Thanks.
What does "input" mean In your program?
Is this what you meant?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

using namespace std;

int main()
{
    cout << "Enter input: " << endl;
    string input;
    getline(cin,input);
    
    size_t pos = input("add")
    
    if(pos != npos)
    {
        cout << "You found it! " << endl;
    }
}
Last edited on
Yup! looked it up in C++ Primer Plus book. Thank you all.
Topic archived. No new replies allowed.