How to read a custom path of a file in c++?

319 views Asked by At

My file is located in C:\\Input\\pStep.p21 . i want to open that file in my cpp program. How can i do it? I am using char* inputPath="C:\\Input\\pStep.p21"; but its not finding my file in program. How to get current working directory in VC++?. Its working if try to save p21 file but failing if i read it.

my code in CAA:

#include<CATSDM_Services>
#include<SdaiModel.h>
#include<CATIUniCodeString>
---
---

main()
{
CATIUniCodeString inputPath("C:\\Input\\pStep.p21");
HRESULT hr=S_OK;
SdaiModel edxModel=Null;
//this method reads express schema name, input p21 file and sdaimodel
 hr=CreateModelFromFile(inputPath,"parts",edxModel);
if(FAILED(hr))
{
cout<<"Model created succesfully";
}
else
{
cout<<"Failed";
}
}
1

There are 1 answers

0
cma On

Sorry for not seeing the question earlier.

From what I am seeing in your code, the test is wrong. The FAILED() macro denotes incorrect execution. Thus from you code, if you see "Failed" on the console, it actually means the execution of the method ran OK.

Change your code to something like:

if ( SUCCEEDED(hr) )
{
    cout<<"Model created succesfully";
}
else
{
    cout<<"Failed";
}