Open file by path specification.

Hi,

Im trying to open a file by its Path Specification, storing the character sequence in a character array. I can do this with strings, but i want to know the error i am getting with a c_string......

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using namespace std;

int main()
{
   char cArray[ 100 ] = {};
   ifstream inFile;

   cout << "Enter a path: ";
   cin.getline( cArray, 100 );

      inFile.open( cArray );
   if ( !inFile.is_open() )
       return -1;   // statement should not execute! It should be open!
   if ( !inFile )
       return -1;  // statement should not execute! I know it exists!

   inFile >> cArray;
   while ( !inFile.eof() ) 
   {
      // parse contents of file
   
   }

   inFile.close();

   cin.ignore();
   return 0;
}


So why cant i specify the path to open the file?
it gets stored in the cArray..

Note that i do not want to append anything.
I just want to open the file by its path. And not by its name.

If i do ios::app, then eof wont work?
Last edited on
I think you meant to use if statements where you have inFile( !inFile.is_open() ) and inFile( !inFile )
omy, i'll never get this fixed now. lol.
Topic archived. No new replies allowed.