Reading from a file

i am trying to read a file which already exist in my system as (proj1_test1.txt) but when i rum my code it didn't print the file. This is the code that i got so far. It is compiling but didn't printing the file and when i enter a wrong file name still its not printing the error message. Any help will be appreciated.


char printFile(){
ifstream file;
file.open("proj1_test1.txt");
string a = " ";

cout << " What is the name of file to import?" << endl;
cin >> a;
if (!file){// == a){
cout << "File" << a << " not opened" << endl;
}


while(file >> a );{
cout << "file loaded " << endl;
}
file.close();
}
Here are the last few lines of your code, indented to show the actual block structure:
1
2
3
4
5
6
    while (file >> a)
        ;
    {
        cout << "file loaded " << endl;
    }
    file.close();
Topic archived. No new replies allowed.