0

Why doesn't my program accept "quit" when I input it?

#include<iostream> 
#include<fstream>
#include<string>
#include <cassert>


using namespace std; 
int main()

{
    ifstream file;
    char filename[20];
    char infile[20];
    int count=-1;
    for(;;)
    {
    cout<<"Enter the file name that you want to open or write 'quit' to exit: ";
    cin>>filename;
    if(filename == "quit")
        break;

    file.open(filename);
    assert(file);
    while(file)
    {
    file>>infile;
    cout<<infile<<" ";
    count++;
    }
    file.clear();
    file.close();
    cout<<endl<<"Words: "<<count<<endl;;
    count=-1;
    }


    system ("PAUSE");
}

Edited by Dani: Fixed formatting

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Sohvkhan
This question has already been answered. 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.