No match for operator!

When I compile, it shows no match for operator!.

1
2
3
4
5
6
7
8
9
10
11
12
13
 cout<<"Would you like to skip file work? (Yes / No)"<<endl<<endl;
    cin>>lol;
    do{
    if(lol=="Yes")
    {
        cout<<"You skip file-work."<<endl<<endl;
        goto skipfile;
    }
    else if(lol=="No")
        cout<<"You don't skip file-work."<<endl<<endl;
    }while(!lol=="Yes"||!lol=="No");
        cout<<"You need to use a capital at beginning, and spell it correctly."<<endl<<endl;
precedence rules. It is interpreting as (!lol) == "Yes"

to check for inequality use `not_eq' or `!='
That fixed the no-match problem, but I got a
In function 'int main()
error: expected primary-expression before 'not_eq' token|
error: expected primary-expression before 'not_eq' token|


1
2
3
4
5
6
7
8
9
10
11
12
13
14
cout<<"Would you like to skip file work? (Yes / No)"<<endl<<endl;
    cin>>lol;
    do{
    if(lol=="Yes")
    {
        cout<<"You skip file-work."<<endl<<endl;
        goto skipfile;
    }
    else if(lol=="No")

        cout<<"You don't skip file-work."<<endl<<endl;
    }while (not_eq lol=="Yes"||not_eq lol=="No");
        cout<<"You need to use a capital at beginning, and spell it correctly."<<endl<<endl;
lol not_eq "Yes" or lol!="No"
Thanks, that fixed that, but I have a new bug.
It doesn't read, it just skips to return 1; Doesn't let you type a file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void FileRead(void){
    char filename[50];
    char word[50];

    ifstream myfiles(filename); 
    cout<<"Please type the name of the file you wish to read."<<endl<<endl;
    cin.getline(filename, 50);
    //if(myfiles)
       // cout<<filename<<" exists, and can now be read."<<endl<<endl;
    // if(!myfiles)
        //cout<<filename<<" doesn't exist, and will not be read."<<endl<<endl;
       //return;
    myfiles.open(filename); 

        myfiles >>word;
        while(myfiles.good()){ 
              cout<<word<<" ";
              myfiles>>word; 
              }



}

Last edited on
On line 5, you are constructing an ifstream object that is attempting to open the file specified by filename. Because filename was never set to anything, it contains some default garbage. When ifstream tries to open that file on line 5, it fails because the file name does not exist.

Instead, you want to get the file name from the command line before attempting to open the file. You can do this by moving
ifstream myfiles(filename);
to line 8.

Also, on line 13, you are trying to open the file again; that will crash and should be removed.


see:
http://www.cplusplus.com/reference/fstream/ifstream/ifstream/
Topic archived. No new replies allowed.