Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 2008 从VS2008解决方案文件中查阅Prolog源代码_Visual Studio 2008_Swi Prolog - Fatal编程技术网

Visual studio 2008 从VS2008解决方案文件中查阅Prolog源代码

Visual studio 2008 从VS2008解决方案文件中查阅Prolog源代码,visual-studio-2008,swi-prolog,Visual Studio 2008,Swi Prolog,我有一个Prolog文件(Hanoi.pl),其中包含用于解决Hanoi Towers难题的代码: hanoi( N ):- move( N, left, middle, right ). move( 0, _, _, _ ):- !. move( N, A, B, C ):- M is N-1, move( M, A, C, B ), inform( A, B ), move( M, C, B, A ). inform( X, Y ):-

我有一个Prolog文件(Hanoi.pl),其中包含用于解决Hanoi Towers难题的代码:

hanoi( N ):-
    move( N, left, middle, right ).

move( 0, _, _, _ ):-
    !.

move( N, A, B, C ):-
    M is N-1,
    move( M, A, C, B ),
    inform( A, B ),
    move( M, C, B, A ).

inform( X, Y ):-
    write( 'move a disk from ' ),
write( X ),
write( ' to ' ),
writeln( Y ).

我还有一个C++文件,它是用VS2008 ID:V/P>编写的

#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
#include "SWI-cpp.h"
#include "SWI-Prolog.h"

predicate_t phanoi;
term_t t0;

int main(int argc, char** argv)
{
    long n = 5;
    int rval;

    if ( !PL_initialise(1, argv) )
        PL_halt(1);

    PL_put_integer( t0, n );

    phanoi = PL_predicate( "hanoi", 1, NULL );

    rval = PL_call_predicate( NULL, PL_Q_NORMAL, phanoi, t0 );

    system( "PAUSE" );
}
#包括
#包括
#包括
#包括
使用名称空间std;
#包括“SWI cpp.h”
#包括“SWI Prolog.h”
谓词_t phanoi;
术语t0;
int main(int argc,字符**argv)
{
长n=5;
int-rval;
如果(!PL_初始化(1,argv))
PL_-halt(1);
PL_put_整数(t0,n);
phanoi=PL_谓词(“hanoi”,1,NULL);
rval=PL_call_谓词(NULL,PL_Q_NORMAL,phanoi,t0);
系统(“暂停”);
}
如何从C++代码中查询我的Prolog源代码(河内?PL)?不是从命令提示符,而是从代码,比如include、consult或compile?它与我的cpp文件位于同一文件夹中

谢谢,

我的Prolog源代码(hanoi.pl)

我的C++代码(在VS2008 IDE中编写)< /P>

#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
#包括“Windows.h”
#包括“ctype.h”
#包括“SWI cpp.h”
#包括“SWI Prolog.h”
#包括“SWI Stream.h”
术语t;
谓词p;
int main(int argc,字符**argv)
{
argc=4;
argv[0]=“libpl.dll”;
argv[1]=“-G32m”;
argv[2]=“-L32m”;
argv[3]=“-T32m”;
PL_初始化(argc,argv);
如果(!PL_初始化(argc,argv))
PL_-halt(1);
PlCall(“咨询(swi('plwin.rc'))”;
PlCall(“咨询('hanoi.pl')”);
int-rval;
长n=3;
PL_put_整数(t,n);
p=PL_谓词(“hanoi”,1,NULL);
rval=PL\u调用谓词(NULL,PL\u Q\u NORMAL,p,t);
PL_暂停(PL_toplevel()?0:1);
}

只需在VS2008中按F5即可构建、编译并运行

我用上面的代码创建了一个简单的项目,但是程序找不到swipl.dll。你有没有让你的代码正确编译和运行?谢谢
hanoi( N ):- 
    move( N, left, middle, right ).

move( 0, _, _, _ ):- 
    !.

move( N, A, B, C ):- 
    M is N-1, 
    move( M, A, C, B ), 
    inform( A, B ), 
    move( M, C, B, A ).

inform( X, Y ):- 
    write( 'move a disk from ' ), 
    write( X ), 
    write( ' to ' ), 
    writeln( Y ). 
#include <iostream>
#include <fstream>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdafx.h>
using namespace std;
#include "Windows.h"
#include "ctype.h"
#include "SWI-cpp.h"
#include "SWI-Prolog.h"
#include "SWI-Stream.h"

term_t t;
predicate_t p;

int main( int argc, char** argv )
{
    argc = 4;

    argv[0] = "libpl.dll";
    argv[1] = "-G32m";
    argv[2] = "-L32m";
    argv[3] = "-T32m";

    PL_initialise(argc, argv);

    if ( !PL_initialise(argc, argv) )
        PL_halt(1);

    PlCall( "consult(swi('plwin.rc'))" );
    PlCall( "consult('hanoi.pl')" );

    int rval;
    long n = 3;
    PL_put_integer( t, n );
    p = PL_predicate( "hanoi", 1, NULL );
    rval = PL_call_predicate( NULL, PL_Q_NORMAL, p, t );

    PL_halt( PL_toplevel() ? 0 : 1 );
}