Opening File

How do I open a file in a sub folder?
The code below isn't working for me...

1
2
3
4
5
string fileA = "dir/book.data";
inFile.open(fileA.c_str());
if(inFile.is_open()){
     //File is open
}
Last edited on
That code should work provided that a both dir/ and dir/book.data exist in the working directory.
Last edited on
The working dir it HTML
the file is in HTML/DIR
therfore being HTML/DIR/book.data

For some reason it's not working
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
29
30
31
32
 string fileA = "author.data";
        string fileB = "book.data";
        location = argv[1];
        type = argv[2];
        key = argv[3];

        cout << "<font color=Pink>" << location << "</font><br>";


        if((location[0]=='H')&&(location[1]=='T')&&(location[2]=='M')&&(location[3]=='L')){
                location = location.erase(0, 5);
                cout << "<font color=Pink> HELLPP</font><br>";
}
        if (location.length() != 0){
                //string temp = "/"
                location = "~/" + location + '/';
        }
        fileA = location + fileA;
        cout << "<font color=Blue>" << fileA << location << type << key << "</font>";
        ifstream inFile;        //File input from the users program call
        //Associates authorData with AuthorInfoData header
        AuthorInfoData authorData;
        //Associates bookData with BookInforData header
        BookInfoData bookData;
        //Variables used to temporarily store information being read in
        string num, fName, lName, code, title, pubCode, type, price, pBack;
        //Variables used to varify data being readin is valid
        string line;
        int count;
        int lineNum;
        inFile.open(fileA.c_str());
        if(inFile.is_open()){


This is actually what i'm doing location is selected by the user, but I'm testing HTML/DIR for variable input and I sill can't execute the file
Topic archived. No new replies allowed.