ifstream infile

Hi,

I am under windows 7 and I try to read a txt file. here is my code

char data[100];

// open a file in write mode.
ofstream outfile;
outfile.open("afile.dat");

cout << "Writing to the file" << endl;
cout << "Enter your name: ";
cin.getline(data, 100);

// write inputted data into the file.
outfile << data << endl;

cout << "Enter your age: ";
cin >> data;
cin.ignore();

// again write inputted data into the file.
outfile << data << endl;

// close the opened file.
outfile.close();

// open a file in read mode.
ifstream infile;
infile.open("test.txt");

cout << "Reading from the file" << endl;
infile >> data;

// write the data at the screen.
cout << data << endl;

// again read the data from the file and display it.
infile >> data;
cout << data << endl;

// close the opened file.
infile.close();

The file "test.txt" is in the same directory as the application, but I can't read it. If I try to read "afile.dat", everything is perfect.. is there any limitation with windows 7? I think I can read what I write, but I dont have the permission to read another file. Is this a restriction of win 7 ? How can I fix this ?
The current directory isn't always what you think when running in an IDE.

Use a system call GetCurrentDirectory() or _getcwd() to confirm the programs working directory.
http://msdn.microsoft.com/en-gb/library/windows/desktop/aa364934(v=vs.85).aspx
http://pubs.opengroup.org/onlinepubs/009604599/
Topic archived. No new replies allowed.