我的代码在Visual Studio和Windows中运行良好,但在Xcode中我遇到了很多问题。首先,我想知道在我删除direct.h include(在Xcode,mac中)后,我收到以下错误
此外,我创建的类中的对象(这与direct.h无关)都无法初始化。 Xcode似乎不理解我的任何构造函数。错误消息如下所示。该示例适用于我的一个对象。有任何帮助吗?
这是我的一个课程。请注意,并非所有课程都没有加载!!
class p_args{
public:
string ts,par,fxd,dir,dato;
int diFL, RSQtype, runtype, *DATO;
int Snow2GlacierOption,Snow2GlacierJulianDay,parallel;//Added 02-12-2012 (extra arguments in args.txt)
int manual,nopt,nopt2,maxn,kstop;
float pcento;
p_args();~p_args();
void getfnames(int);
};
p_args::p_args(){};
p_args::~p_args(){};
void p_args::getfnames(int plots){//read file names
int i=0;
this->DATO=new int[3];
ifstream inFile;
inFile.open("ARGS.txt",ios::in);
if (inFile.is_open()){
inFile>>this->dir;cout<<"Dir\t"<<this->dir<<"\n";
inFile>>this->ts;cout<<"ts\t"<<this->ts<<"\n";
inFile>>this->par;cout<<"par\t"<<this->par<<"\n";
inFile>>this->fxd;cout<<"fxd\t"<<this->fxd<<"\n";
inFile>>this->diFL; // multiple lapse
inFile>>this->manual;//manual control of calib.
inFile>>this->nopt;
inFile>>this->nopt2;
inFile>>this->maxn;
inFile>>this->kstop;
inFile>>this->pcento;
inFile>>this->dato;cout<<lnz<<"BEGIN =\t"<<this->dato<<"\n";
if(plots==1){ //Use with Grapher
this->DATO = breakdotstring(dato);
cout<<this->DATO[0]<<"-"<<this->DATO[1]<<"-"<<this->DATO[2]<<"\n";
//cin.get();
}
inFile>>this->RSQtype;
if(this->RSQtype==0){cout<<"RSQ = NASH SUTCLIFFE (NSEFF)"<<"\n";} else {cout<<"RSQ = NASH SUTCLIFFE *(1-VOLUMETRIC_ERROR)"<<"\n";}
inFile>>this->runtype;
if(this->runtype==0)cout<<"SIMULATING WITH GIVEN PARAMETERS\n";
if(this->runtype==1)cout<<"PARAMETER STUDY RUN";
if((this->runtype!=0) & (this->runtype!=1) ){cout<<"OPTIMISING RUN";}
cout<<lnz;
inFile>>this->Snow2GlacierOption;//Added 02-12-2012 (extra arguments in args.txt)
cout<<this->Snow2GlacierOption<<"--Snow2GlacierOption\n";
inFile>>this->Snow2GlacierJulianDay;//Added 02-12-2012 (extra arguments in args.txt)
cout<<this->Snow2GlacierJulianDay<<"--Snow2GlacierJulianDay\n";
if(this->Snow2GlacierOption==0)cout<<"Snow Storage On Julian Day["<<this->Snow2GlacierJulianDay<<"] Not Converted to Glacier\n";//Added 02-12-2012 (extra arguments in args.txt)
if(this->Snow2GlacierOption==1)cout<<"Snow Storage On Julian Day["<<this->Snow2GlacierJulianDay<<"] Converted(Zeroed)\n";//Added 02-12-2012 (extra arguments in args.txt)
cout<<lnz;//Added 02-12-2012 (extra arguments in args.txt)
inFile>>this->parallel;//Added 02-12-2012 (extra arguments in args.txt)
//cout<<this->parallel<<"-->1=Parallel/0=Serial Simulation\n";
if(this->parallel==0)cout<<"SERIAL HBV SIMULATIONS\n";//Added 02-12-2012 (extra arguments in args.txt)
if(this->parallel==1)cout<<"PARALLEL HBV SIMULATIONS\nEach simulation is 1 Hydrological year\n";//Added 02-12-2012 (extra arguments in args.txt)
cout<<lnz;//Added 02-12-2012 (extra arguments in args.txt)
inFile.close();
}
}
答案 0 :(得分:0)
我找到了从https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/getcwd.3.html处理Xcode中的getwcd的方法。该解决方案类似于@Cyber建议的解决方案。我必须在头文件中进行以下更改;
//#include <direct.h> // for _getcwd WIN
#include <unistd.h> // for getcwd Mac
并使用
getcwd()
而不是
_getcwd()
在我的功能中
void GetCurrentPath(char* buffer){getcwd(buffer,PATH_MAX);}
然后在我的函数main()中使用了
//Curent path
char current_path[PATH_MAX]; //CurrentPath[_MAX_PATH]; windows
GetCurrentPath(current_path);
cout << current_path << endl;
通过查看头文件解决了我的问题的第二部分。我曾使用Xcode创建空头文件hbv.h然后我错误地粘贴了我在#endif
下面而不是#endif
以上的VC ++中使用的旧版hbv.h文件中的代码
#ifndef hbvOptimMAC_hbv_h
#define hbvOptimMAC_hbv_h
//<code defining classes was correctly pasted here>
#endif
//<code defining classes initially mistakenly pasted here>