in Education by
I am developing a prototype for a game, and certain gameplay rules are to be defined in an ini file so that the game designers can tweak the game parameters without requiring help from me in addition to a re-compile. This is what I'm doing currently: std::ifstream stream; stream.open("rules.ini"); if (!stream.is_open()) { throw new std::exception("Rule file could not be opened"); } // read file contents here stream.close(); However, my stream never opens succesfully. Diving deep into the STL source during debugging reveals that _getstream() (as defined in stream.c) keeps on returning NULL, but I just can't figure out why this is. Help, anyone? Edit: Rules.ini is in the same directory as the .exe file. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You are assuming that the working directory is the directory that your executable resides in. That is a bad assumption. Your executable can be run from any working directory, so it's usually a bad idea to hard-code relative paths in your software. If you want to be able to access files relative to the location of your executable, you should first determine the path of your executable and create a fully qualified path from that. You can get the name of your executable by examining the argv[0] parameter passed to main(). Alternatively, if you're on Windows, you can get it with GetModuleFileName() by passing NULL as the first parameter.

Related questions

0 votes
    I am developing a prototype for a game, and certain gameplay rules are to be defined in an ini ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    I am developing a prototype for a game, and certain gameplay rules are to be defined in an ini ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 10, 2022 in Education by JackTerrance
0 votes
    I am developing a prototype for a game, and certain gameplay rules are to be defined in an ini ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 10, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Generic iterator (3 answers) Closed 7 years ago. Suppose I want to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Generic iterator (3 answers) Closed 7 years ago. Suppose I want to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Generic iterator (3 answers) Closed 7 years ago. Suppose I want to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 15, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Generic iterator (3 answers) Closed 7 years ago. Suppose I want to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 13, 2022 in Education by JackTerrance
0 votes
    I want something like an std::map, but I only want to see if the item exists or not, I don' ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 12, 2022 in Education by JackTerrance
0 votes
    In the following code : #include #include #include using namespace std; int main() { string x = "This ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    In the following code : #include #include #include using namespace std; int main() { string x = "This ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    I have a c++11 type alias: using coord = std::array; Can I define the operator + for coord? ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 29, 2022 in Education by JackTerrance
0 votes
    I have a c++11 type alias: using coord = std::array; Can I define the operator + for coord? ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I have a c++11 type alias: using coord = std::array; Can I define the operator + for coord? ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 22, 2022 in Education by JackTerrance
0 votes
    Maps are great to get things done easily, but they are memory hogs and suffer from caching issues. And ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    Maps are great to get things done easily, but they are memory hogs and suffer from caching issues. And ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
...