View Single Post
Old 28-04-2005, 06:07 PM   #6
Data
retired
 
Data's Avatar


 
Join Date: Jun 2004
Location: Jan Mayen, Svalbard and Jan Mayen
Posts: 2,167
Default

with file exists check:

Code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main()
{
 *cout<<"Which file do you want to open?" << endl;
 *string name;
 *cin >> name;
 *cout << "Opening "<< name << "..." << endl;
 *ifstream file (name.c_str());
 *if(!file) {
 * * cout <<"file: "<< name << " doesn't exist" <<endl;
 * * return 1;
 *}

 *cout << file.rdbuf();
 *cin.get();
 *return 0;
}
__________________
Flowing with the stream of life
Data is offline                         Send a private message to Data
Reply With Quote