The following program gives different results when executed from CodeBlocks and from cmd -:
#include <iostream>
Exiting CodeBlocks after starting from within the IDE:
output = 0 !!!
The result from cmd by executing boost1 after changing the current directory to the folder containing the executable file (the source path specified in the code) is:
output = 1 !!!
For me, the result set by CodeBlocks should be correct.
I run this program on the 64-bit version of Windows 7 SP1 and CodeBlocks 13.12.
I am using TDM-GCC 4.9.2 (32-bit) and Boost 1.57 to create this program.
Wrong output from cmd appears only if I run the program after changing the current directory to the folder containing the executable file.
If I save the current cmd directory in a different folder, the correct output is displayed.
EDIT -:
The original problem I was trying to solve was to check if the file / directory was a descendant of another directory or not.
To do this, I executed the following code:
#include <iostream>
Now, if I executed the code with argv[1]="D:\anmol\coding\c++\boost\boost1\bin\release" and argv[2]="D:\anmol\coding\c++\boost\boost1\bin" , it will return true when it should return false . (Since in this case parent is actually a descendant descendant )
The reason for this is that during the while loop in HeightDiff() after some iterations, the descendant takes on the value D: Therefore, equivalent() will return true and stop the loop one step before the descendant becomes an empty string.
I did not know before that D: refers to the current directory and therefore asks this question.
Is there a way to change the HeightDiff function so that it HeightDiff correct result?
Will replacing the equivalent() condition with while(descendant != parent) give the correct output in all cases?
If not, is there another solution?