在C#.NET中运行C ++代码 [英] Run C++ code in C#.NET
问题描述
一位商业伙伴告诉我,我应该能够在
C#.NET环境中运行C ++代码,因为C ++和C#属于同一个系列。
他发给我下面的代码并要求我在C#.NET环境中运行。我b $ b得到了很多编译错误,因为#include的东西不存在于
C#中!谁能告诉我下面的代码是否应该在C#.NET中运行?
----------------------- -------------------------------------------------- -------------------------------------------------- ----
// #define NO_NEWIO
#include< iostream>
///包含CONNECT / C ++
#include" stdafx.h"
#include" stdafx.cpp"
/ / #include" sconnect.h"
#include" c:\\data \\Splus61包含\\EasyEngineConnect.h"
#include" c:\\data \\ Splus61包含\\EasyEngineConnect.cpp"
#include" c:\\\ \\\ Splus61包含\\EasyCharacter.h"
// #include" c:\\data \\Splus61包含\\EasyCharacter.cpp" ;
#include" c:\\data \\Splus61包含\ \ EasyMatrix.h"
// #include" c:\\data \\Splus61包含\\EasyMatrix.cpp"
#include" c:\\data \\ Splus61包含\\EasyNumeric.h"
// #include" c:\\data \\ \\\Splus61包含\\EasyNumeric.cpp"
使用命名空间std;
int main(int argc,char * argv [])
{
//连接到S +
EasyEngineConnect easyconnect_(argc,argv);
///创建矩阵9x9元素。
// EasyMatrix x;
//x.Create("matrix(1:9,nrow = 9, ncol = 9)"," x");
//创建矩阵9x9元素。
// EasyMatrix y;
/ /y.Create("matrix(1:9,nrow = 9,ncol = 9)"," y");
CSPobject Y;
if(!Y.Create(" vector(\" double \",10.6)"))
{
cout< < 无法创建矢量。 <<结束;
返回1;
}
CSPobject X1;
if(!X1。创建(vector(\double \,8.6)"))
{
cout<< 无法创建矢量。 <<结束;
返回1;
}
CSPobject X2;
if(!X2.Create(") vector(\" double \,3.4)"))
{
cout<< 无法创建矢量。 <<结束;
返回1;
}
///连接到S +
// CSPengineConnect engineConnect(argc,argv); // EasyEngineConnect
easyconnect_(argc,argv);
///创建矩阵9x9元素。
CSPmatrix x;
x.Create(" matrix(1:9,nrow = 9,ncol = 9)"," x");
CSPnumeric sx ;
sx.Create(" 1:10"," x");
CSPnumeric sy = sx * sx;
sy .Assign(" y);
// engineConnect.SyncParseEval(" z< -lm(y~x)");
/ *
CSPengineConnect engineConnect(argc,argv);
CSPobject x;
///创建矩阵24x400 elem。
x.Create(" matrix(1:223,nrow = 24,ncol = 400)");
//x.Create("matrix(1.2) ,nrow =,ncol = 10)");
CSPobject y;
///创建矩阵24x400元素。
y.Create (" matrix(231:1,nrow = 24,ncol = 400)");
///分配。
x.Assign(" x" );
y.Assign(" y");
///调用S +回归" z< -x + y"。
int iSuccess = engineConnect.SyncParseEval(" z< -x + y");
///错误。
if(iSuccess = = 0)
{
cout<< 错误,无法调用\z< ;-( x + y)\"" << endl;
返回1;
}
CSPmatrix z(engineConnect.get(" z"));
if(!z.IsValid())
{
cout<< 错误,无法搜索对象z << endl;
}
///打印。
for(int i = 1; i< = 5; i ++); //z.GetNRow(); ++ i)
{
for(int j = 1; j< = z.GetNCol(); ++ j)
{
cout<< (double)z(i,j)<< " " ;;
}
cout<<结束;
}
/ *
//创建与S-PLUS的连接
CSPengineConnect engineConnect(argc,argv);
///创建向量24.
CSPobject A_vector;
if(!A_vector) .Create(" vector(\double \,10)"))
{
cout<< 无法创建矢量。 << endl;
返回1;
}
CSPobject B_matrix;
if(!B_matrix.Create(")矩阵(1.2,nrow = 10,ncol = 10)))
{
cout<< 无法创建矩阵。 << endl;
返回1;
}
/// C_matrix = B_matrix + A_vector。
CSPmatrix C_matrix( B_matrix + A_vector);
if(C_matrix == NULL)
{
cout<< 无法创建矩阵。 <<结束;
}
* /
/ *
CSPnumeric sx;
sx.Create(" 1:10"," x");
CSPnumeric sy = sx * sx;
sy.Assign(" y");
engineConnect.SyncParseEval(" z< -lm(y~x)");
* /
/ *
///打印C_matrix。
cout<< Print C_matrix = B_matrix + A_vector。 << endl<< endl;
for(int i = 1; i< = C_matrix.nrow(); ++ i)
{
for( int j = 1; j< = C_matrix.ncol(); ++ j)
{
cout<< (double)C_matrix(i,j)<< "英寸; //<出去控制台。
}
cout<< endl;
}
cout<< endl<<结束;
getchar();
///调用程序S +。
CSPcharacter returnObj;
///用一个元素创建一个整数向量
///表示传递给函数''对象'的一个参数'
CSPinteger args(1);
///创建一个CSPcall对象
CSPcall sCall;
///调用函数S + (objects())。
cout<< 调用函数S +(对象(1)).... << endl<< endl;
sCall.Create(" objects",args);
/// Call。
returnObj = sCall.Eval() ; //对象(1)
if(returnObj == NULL)
{
cout<< 功能对象S +失败 <<结束;
返回1;
}
///获取数量。
int数量= returnObj.length();
cout<< 数量对象: <<数量<< endl;
///打印对象。
for(i = 0; i< quantity; ++ i)
{
cout<< " [" << i + 1<< " ] << (char *)returnObj [i]<<结束;
}
* /
/ *
//创建与S的连接-PLUS
g_engineConnect.Create(argc,argv);
//创建名称为x的S对象在当前数据库中。
//在命令行中与x< -1:10相同。
CSPnumeric sx;
sx.Create (1:10,x);
// Squaring sx,与本地
frame,
//但是在这里我们将它设置为本地C ++变量sy。
CSPnumeric sy = sx * sx;
//将结果分配为名称为y的S对象在当前的
数据库中。
sy.Assign(" y);
//评估z< -lm (y~x)
g_engineConnect.SyncParseEval(" z< -lm(y~x)");
也许----- -------------- CSPobject Eval(" z< -lm(y~x)");
//第二个例子
CSPevaluator s;
CSPcharacter消息("''hello''");
message.Print();
// CSPmatrix M(矩阵(1:4,rnow = 2));
//M.Print();
* /
printf(正常终止\ n);
返回0;
}
好奇 < fi ******** @ yahoo.com写了留言
新闻:1d ********************** ************ @ u57g2000 hsf.googlegroups.com ...
>一位商业伙伴告诉我,我应该能够在
C#.NET环境中运行C ++代码,因为C ++和C#属于同一个系列。
他给我发了以下代码并要求我运行在C#.NET环境中。我b $ b得到了很多编译错误,因为#include的东西不存在于
C#中!谁能告诉我下面的代码是否应该在C#.NET中运行?
仅仅因为C ++有大括号并不意味着C#编译器理解它的结构是什么。
尝试编译:
http://www.microsoft。 com / express / vc /
-
Gregory A. Beamer
MVP,MCP:+ I ,SE,SD,DBA
订阅我的博客
http://feeds.feedburner.com/GregoryBeamer#
或只是阅读它:
http://feeds.feedburner.com/GregoryBeamer
*** *****************************************
|创造性思考! |
***************************************** ***
只有最简单的示例方法才能在C#和C ++中编译。并且
这只是针对个别方法。整个应用程序永远不会在两者中编译
。通常,C#将无法编译C ++代码和C ++
将无法编译C#代码。您选择的任何一对
语言都是如此。
-
http://www.tangiblesoftwaresolutions.com
C ++到C#
C ++到VB
C ++ to Java
VB& C#to Java
Java to VB& C#
即时C#:VB到C#
即时VB:C#到VB
即时C ++:VB,C#或Java到C ++ / CLI
好奇写道:
一位商业伙伴告诉我,我应该能够在
C#.NET环境中运行C ++代码,因为C ++和C#属于同一个家庭。
他给我发了下面的代码并要求我在C#.NET环境中运行。我b $ b得到了很多编译错误,因为#include的东西不存在于
C#中!谁能告诉我下面的代码是否应该在C#.NET中运行?
----------------------- -------------------------------------------------- -------------------------------------------------- ----
// #define NO_NEWIO
#include< iostream>
///包含CONNECT / C ++
#include" stdafx.h"
#include" stdafx.cpp"
/ / #include" sconnect.h"
#include" c:\\data \\Splus61包含\\EasyEngineConnect.h"
#include" c:\\data \\ Splus61包含\\EasyEngineConnect.cpp"
#include" c:\\\ \\\ Splus61包含\\EasyCharacter.h"
// #include" c:\\data \\Splus61包含\\EasyCharacter.cpp" ;
#include" c:\\data \\Splus61包含\\ E asyMatrix.h"
// #include" c:\\data \\ Splus61包含\\EasyMatrix.cpp"
#include" c:\\data \\Splus61包含\\EasyNumeric.h"
// #include" c:\\data \\\ \\ Splus61包含\\EasyNumeric.cpp"
使用命名空间std;
int main(int argc,char * argv [] )
{
//连接到S +
EasyEngineConnect easyconnect_(argc,argv);
///创建矩阵9x9元素。
// EasyMatrix x;
//x.Create("matrix(1:9,nrow = 9,ncol = 9)"," x");
//创建矩阵9x9 elem。
// EasyMatrix y;
// y .Create(" matrix(1:9,nrow = 9,ncol = 9)"," y");
CSPobject Y;
if(!Y.Create(" vector(\double \,10.6)"))
{
cout<< 无法创建矢量。 <<结束;
返回1;
}
CSPobject X1;
if(!X1。创建(vector(\double \,8.6)"))
{
cout<< 无法创建矢量。 <<结束;
返回1;
}
CSPobject X2;
if(!X2.Create(") vector(\" double \,3.4)"))
{
cout<< 无法创建矢量。 <<结束;
返回1;
}
///连接到S +
// CSPengineConnect engineConnect(argc,argv); // EasyEngineConnect
easyconnect_(argc,argv);
///创建矩阵9x9元素。
CSPmatrix x;
x.Create(" matrix(1:9,nrow = 9,ncol = 9)"," x");
CSPnumeric sx ;
sx.Create(" 1:10"," x");
CSPnumeric sy = sx * sx;
sy .Assign(" y);
// engineConnect.SyncParseEval(" z< -lm(y~x)");
/ *
CSPengineConnect engineConnect(argc,argv);
CSPobject x;
///创建矩阵24x400 elem。
x.Create(" matrix(1:223,nrow = 24,ncol = 400)");
//x.Create(" ;矩阵(1.2,nrow =,ncol = 10)");
CSPobject y;
///创建矩阵24x400元素。
y.Create(" matrix(231:1,nrow = 24,ncol = 400)");
///分配。
x.Assign( " x");
y.Assign(" y");
///致电S + regressio n" z< -x + y"。
int iSuccess = engineConnect.SyncParseEval(" z< -x + y");
///错误。
if(iSuccess == 0)
{
cout<< 错误,无法调用\z< ;-( x + y)\"" << endl;
返回1;
}
CSPmatrix z(engineConnect.get(" z"));
if(!z.IsValid())
{
cout<< 错误,无法搜索对象z << endl;
}
///打印。
for(int i = 1; i< = 5; i ++); //z.GetNRow(); ++ i)
{
for(int j = 1; j< = z.GetNCol(); ++ j)
{
cout<< (double)z(i,j)<< " " ;;
}
cout<<结束;
}
/ *
//创建与S-PLUS的连接
CSPengineConnect engineConnect(argc,argv);
///创建向量24.
CSPobject A_vector;
if(!A_vector) .Create(" vector(\double \,10)"))
{
cout<< 无法创建矢量。 << endl;
返回1;
}
CSPobject B_matrix;
if(!B_matrix.Create(")矩阵(1.2,nrow = 10,ncol = 10)))
{
cout<< 无法创建矩阵。 << endl;
返回1;
}
/// C_matrix = B_matrix + A_vector。
CSPmatrix C_matrix( B_matrix + A_vector);
if(C_matrix == NULL)
{
cout<< 无法创建矩阵。 <<结束;
}
* /
/ *
CSPnumeric sx;
sx.Create(" 1:10"," x");
CSPnumeric sy = sx * sx;
sy.Assign(" y");
engineConnect.SyncParseEval(" z< -lm(y~x)");
* /
/ *
///打印C_matrix。
cout<< Print C_matrix = B_matrix + A_vector。 << endl<< endl;
for(int i = 1; i< = C_matrix.nrow(); ++ i)
{
for( int j = 1; j< = C_matrix.ncol(); ++ j)
{
cout<< (double)C_matrix(i,j)<< "英寸; //<出去控制台。
}
cout<< endl;
}
cout<< endl<<结束;
getchar();
///调用程序S +。
CSPcharacter returnObj;
///用一个元素创建一个整数向量
///表示传递给函数''对象'的一个参数'
CSPinteger args(1);
///创建一个CSPcall对象
CSPcall sCall;
///调用函数S + (objects())。
cout<< 调用函数S +(对象(1)).... << endl<< endl;
sCall.Create(" objects",args);
/// Call。
returnObj = sCall.Eval() ; //对象(1)
if(returnObj == NULL)
{
cout<< 功能对象S +失败 <<结束;
返回1;
}
///获取数量。
int数量= returnObj.length();
cout<< 数量对象: <<数量<< endl;
///打印对象。
for(i = 0; i< quantity; ++ i)
{
cout<< " [" << i + 1<< " ] << (char *)returnObj [i]<<结束;
}
* /
/ *
//创建与S的连接-PLUS
g_engineConnect.Create(argc,argv);
//创建名称为x的S对象在当前数据库中。
//在命令行中与x< -1:10相同。
CSPnumeric sx;
sx.Create (1:10,x);
// Squaring sx,与本地
frame,
//但是在这里我们将它设置为本地C ++变量sy。
CSPnumeric sy = sx * sx;
//将结果分配为名称为y的S对象在当前的
数据库中。
sy.Assign(" y);
//评估z< -lm (y~x)
g_engineConnect.SyncParseEval(" z< -lm(y~x)");
也许----- -------------- CSPobject Eval(" z< -lm(y~x)");
//第二个例子
CSPevaluator s;
CSPcharacter消息("''hello''");
message.Print();
// CSPmatrix M(矩阵(1:4,rnow = 2));
//M.Print();
* /
printf(正常终止\ n);
返回0;
}
2008年10月28日星期二07:07:37 -0700(PDT),Curious写道:
< blockquote class =post_quotes>
一位商业伙伴告诉我,我应该能够在
C#.NET环境中运行C ++代码,因为C ++和C#属于同一个系列。
您的业务伙伴错了。
现在,有一个用于.NET框架的C ++版本,名为C ++ / CLI,但是
需要进行典型的某些更改才能使一般的
C ++程序适应它。
>
A business associate told me that I should be able to run C++ code in
C#.NET environment because C++ and C# belong to the same family.
He sent me the code below and asked me to run in C#.NET environment. I
got numerous compiling errors because #include stuff don''t exist in
C#! Could anyone tell me if the code below should run in C#.NET?
-------------------------------------------------------------------------------------------------------------------------------
//#define NO_NEWIO
#include <iostream>
/// Include for CONNECT/C++
#include "stdafx.h"
#include "stdafx.cpp"
//#include "sconnect.h"
#include "c:\\data\\Splus61 Includes\\EasyEngineConnect.h"
#include "c:\\data\\Splus61 Includes\\EasyEngineConnect.cpp"
#include "c:\\data\\Splus61 Includes\\EasyCharacter.h"
//#include "c:\\data\\Splus61 Includes\\EasyCharacter.cpp"
#include "c:\\data\\Splus61 Includes\\EasyMatrix.h"
//#include "c:\\data\\Splus61 Includes\\EasyMatrix.cpp"
#include "c:\\data\\Splus61 Includes\\EasyNumeric.h"
//#include "c:\\data\\Splus61 Includes\\EasyNumeric.cpp"
using namespace std;
int main(int argc, char* argv[])
{
// Connect to S+
EasyEngineConnect easyconnect_(argc, argv);
/// Create matrix 9x9 elem.
//EasyMatrix x;
//x.Create("matrix(1:9, nrow=9, ncol=9)", "x");
// Create matrix 9x9 elem.
//EasyMatrix y;
//y.Create("matrix(1:9, nrow=9, ncol=9)", "y");
CSPobject Y;
if (!Y.Create("vector(\"double\",10.6)"))
{
cout << "Can not create vector." << endl;
return 1;
}
CSPobject X1;
if (!X1.Create("vector(\"double\",8.6)"))
{
cout << "Can not create vector." << endl;
return 1;
}
CSPobject X2;
if (!X2.Create("vector(\"double\",3.4)"))
{
cout << "Can not create vector." << endl;
return 1;
}
/// Connect to S+
// CSPengineConnect engineConnect(argc, argv); //EasyEngineConnect
easyconnect_(argc, argv);
/// Create matrix 9x9 elem.
CSPmatrix x;
x.Create("matrix(1:9, nrow=9, ncol=9)", "x");
CSPnumeric sx;
sx.Create("1:10","x");
CSPnumeric sy = sx * sx;
sy.Assign("y");
// engineConnect.SyncParseEval("z<-lm(y~x)");
/*
CSPengineConnect engineConnect(argc, argv);
CSPobject x;
/// Create matrix 24x400 elem.
x.Create("matrix(1:223, nrow=24, ncol=400)");
//x.Create("matrix(1.2, nrow=, ncol=10)");
CSPobject y;
/// Create matrix 24x400 elem.
y.Create("matrix(231:1, nrow=24, ncol=400)");
/// Assign.
x.Assign("x");
y.Assign("y");
/// Call S+ regression "z<-x+y".
int iSuccess = engineConnect.SyncParseEval("z<-x+y");
/// Error.
if (iSuccess == 0)
{
cout << "Error, Can not call \"z<-(x+y)\"" << endl;
return 1;
}
CSPmatrix z(engineConnect.get("z"));
if (!z.IsValid())
{
cout << "Error, Can not search object z" << endl;
}
/// Print.
for (int i = 1; i <= 5;i++); //z.GetNRow(); ++i)
{
for (int j = 1; j <= z.GetNCol(); ++j)
{
cout << (double)z(i, j) << " ";
}
cout << endl;
}
/*
//Create the connection to S-PLUS
CSPengineConnect engineConnect(argc, argv);
/// Create vector 24.
CSPobject A_vector;
if (!A_vector.Create("vector(\"double\",10)"))
{
cout << "Can not create vector." << endl;
return 1;
}
CSPobject B_matrix;
if (!B_matrix.Create("matrix(1.2, nrow=10, ncol=10)"))
{
cout << "Can not create matrix." << endl;
return 1;
}
/// C_matrix = B_matrix + A_vector.
CSPmatrix C_matrix(B_matrix + A_vector) ;
if (C_matrix == NULL)
{
cout << "Can not create matrix." << endl;
}
*/
/*
CSPnumeric sx;
sx.Create("1:10","x");
CSPnumeric sy = sx * sx;
sy.Assign("y");
engineConnect.SyncParseEval("z<-lm(y~x)");
*/
/*
/// Print C_matrix.
cout << "Print C_matrix = B_matrix + A_vector." << endl << endl;
for (int i = 1; i <= C_matrix.nrow(); ++i)
{
for (int j = 1; j <= C_matrix.ncol(); ++j)
{
cout << (double)C_matrix(i,j) << " "; //< Out to console.
}
cout << endl;
}
cout << endl << endl;
getchar();
/// Call procedure S+.
CSPcharacter returnObj;
/// Create a integer vector with one element
/// representing one argument to pass to function ''objects''
CSPinteger args("1");
/// Create a CSPcall object
CSPcall sCall;
/// Call function S+ (objects()).
cout << "Call function S+ (objects(1))...." << endl << endl;
sCall.Create("objects", args);
/// Call.
returnObj = sCall.Eval(); // objects(1)
if (returnObj == NULL)
{
cout << "Function objects S+ failed" << endl;
return 1;
}
/// Get quantity.
int quantity = returnObj.length();
cout << "Quantity objects : " << quantity << endl;
/// Print objects.
for (i = 0; i < quantity; ++i)
{
cout << " [ " << i+1 << " ] " << (char *)returnObj[i] << endl;
}
*/
/*
//Create the connection to S-PLUS
g_engineConnect.Create( argc, argv);
//Create S object with name "x" in the current database.
//Same as x<-1:10 at the command line.
CSPnumeric sx;
sx.Create("1:10","x");
//Squaring sx, which is the same as S expression sy <- x*x in a local
frame,
//but here we set it to local C++ variable sy.
CSPnumeric sy = sx * sx;
// Assign the result as S object with name "y" in the current
database.
sy.Assign("y");
//Evaluate z<-lm(y~x)
g_engineConnect.SyncParseEval("z<-lm(y~x)");
maybe ------------------- CSPobject Eval ("z<-lm(y~x)");
//second example
CSPevaluator s;
CSPcharacter message("''hello''");
message.Print();
//CSPmatrix M("matrix(1:4,rnow=2)");
//M.Print();
*/
printf("Normal Termination\n");
return 0;
}
"Curious" <fi********@yahoo.comwrote in message
news:1d**********************************@u57g2000 hsf.googlegroups.com...>A business associate told me that I should be able to run C++ code in
C#.NET environment because C++ and C# belong to the same family.
He sent me the code below and asked me to run in C#.NET environment. I
got numerous compiling errors because #include stuff don''t exist in
C#! Could anyone tell me if the code below should run in C#.NET?Just because C++ has curly braces does not mean the C# compiler understands
its constructs.
Try this to compile:
http://www.microsoft.com/express/vc/
--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA
Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#
or just read it:
http://feeds.feedburner.com/GregoryBeamer
********************************************
| Think outside the box! |
********************************************
Only the most trivial example methods will compile in both C# and C++. And
this is looking only at individual methods. Entire applications will never
compile in both. In general, C# will not be able to compile C++ code and C++
will not be able to compile C# code. The same will be true for any pair of
languages you choose.
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
VB & C# to Java
Java to VB & C#
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB, C#, or Java to C++/CLI
"Curious" wrote:
A business associate told me that I should be able to run C++ code in
C#.NET environment because C++ and C# belong to the same family.
He sent me the code below and asked me to run in C#.NET environment. I
got numerous compiling errors because #include stuff don''t exist in
C#! Could anyone tell me if the code below should run in C#.NET?
-------------------------------------------------------------------------------------------------------------------------------
//#define NO_NEWIO
#include <iostream>
/// Include for CONNECT/C++
#include "stdafx.h"
#include "stdafx.cpp"
//#include "sconnect.h"
#include "c:\\data\\Splus61 Includes\\EasyEngineConnect.h"
#include "c:\\data\\Splus61 Includes\\EasyEngineConnect.cpp"
#include "c:\\data\\Splus61 Includes\\EasyCharacter.h"
//#include "c:\\data\\Splus61 Includes\\EasyCharacter.cpp"
#include "c:\\data\\Splus61 Includes\\EasyMatrix.h"
//#include "c:\\data\\Splus61 Includes\\EasyMatrix.cpp"
#include "c:\\data\\Splus61 Includes\\EasyNumeric.h"
//#include "c:\\data\\Splus61 Includes\\EasyNumeric.cpp"
using namespace std;
int main(int argc, char* argv[])
{
// Connect to S+
EasyEngineConnect easyconnect_(argc, argv);
/// Create matrix 9x9 elem.
//EasyMatrix x;
//x.Create("matrix(1:9, nrow=9, ncol=9)", "x");
// Create matrix 9x9 elem.
//EasyMatrix y;
//y.Create("matrix(1:9, nrow=9, ncol=9)", "y");
CSPobject Y;
if (!Y.Create("vector(\"double\",10.6)"))
{
cout << "Can not create vector." << endl;
return 1;
}
CSPobject X1;
if (!X1.Create("vector(\"double\",8.6)"))
{
cout << "Can not create vector." << endl;
return 1;
}
CSPobject X2;
if (!X2.Create("vector(\"double\",3.4)"))
{
cout << "Can not create vector." << endl;
return 1;
}
/// Connect to S+
// CSPengineConnect engineConnect(argc, argv); //EasyEngineConnect
easyconnect_(argc, argv);
/// Create matrix 9x9 elem.
CSPmatrix x;
x.Create("matrix(1:9, nrow=9, ncol=9)", "x");
CSPnumeric sx;
sx.Create("1:10","x");
CSPnumeric sy = sx * sx;
sy.Assign("y");
// engineConnect.SyncParseEval("z<-lm(y~x)");
/*
CSPengineConnect engineConnect(argc, argv);
CSPobject x;
/// Create matrix 24x400 elem.
x.Create("matrix(1:223, nrow=24, ncol=400)");
//x.Create("matrix(1.2, nrow=, ncol=10)");
CSPobject y;
/// Create matrix 24x400 elem.
y.Create("matrix(231:1, nrow=24, ncol=400)");
/// Assign.
x.Assign("x");
y.Assign("y");
/// Call S+ regression "z<-x+y".
int iSuccess = engineConnect.SyncParseEval("z<-x+y");
/// Error.
if (iSuccess == 0)
{
cout << "Error, Can not call \"z<-(x+y)\"" << endl;
return 1;
}
CSPmatrix z(engineConnect.get("z"));
if (!z.IsValid())
{
cout << "Error, Can not search object z" << endl;
}
/// Print.
for (int i = 1; i <= 5;i++); //z.GetNRow(); ++i)
{
for (int j = 1; j <= z.GetNCol(); ++j)
{
cout << (double)z(i, j) << " ";
}
cout << endl;
}
/*
//Create the connection to S-PLUS
CSPengineConnect engineConnect(argc, argv);
/// Create vector 24.
CSPobject A_vector;
if (!A_vector.Create("vector(\"double\",10)"))
{
cout << "Can not create vector." << endl;
return 1;
}
CSPobject B_matrix;
if (!B_matrix.Create("matrix(1.2, nrow=10, ncol=10)"))
{
cout << "Can not create matrix." << endl;
return 1;
}
/// C_matrix = B_matrix + A_vector.
CSPmatrix C_matrix(B_matrix + A_vector) ;
if (C_matrix == NULL)
{
cout << "Can not create matrix." << endl;
}
*/
/*
CSPnumeric sx;
sx.Create("1:10","x");
CSPnumeric sy = sx * sx;
sy.Assign("y");
engineConnect.SyncParseEval("z<-lm(y~x)");
*/
/*
/// Print C_matrix.
cout << "Print C_matrix = B_matrix + A_vector." << endl << endl;
for (int i = 1; i <= C_matrix.nrow(); ++i)
{
for (int j = 1; j <= C_matrix.ncol(); ++j)
{
cout << (double)C_matrix(i,j) << " "; //< Out to console.
}
cout << endl;
}
cout << endl << endl;
getchar();
/// Call procedure S+.
CSPcharacter returnObj;
/// Create a integer vector with one element
/// representing one argument to pass to function ''objects''
CSPinteger args("1");
/// Create a CSPcall object
CSPcall sCall;
/// Call function S+ (objects()).
cout << "Call function S+ (objects(1))...." << endl << endl;
sCall.Create("objects", args);
/// Call.
returnObj = sCall.Eval(); // objects(1)
if (returnObj == NULL)
{
cout << "Function objects S+ failed" << endl;
return 1;
}
/// Get quantity.
int quantity = returnObj.length();
cout << "Quantity objects : " << quantity << endl;
/// Print objects.
for (i = 0; i < quantity; ++i)
{
cout << " [ " << i+1 << " ] " << (char *)returnObj[i] << endl;
}
*/
/*
//Create the connection to S-PLUS
g_engineConnect.Create( argc, argv);
//Create S object with name "x" in the current database.
//Same as x<-1:10 at the command line.
CSPnumeric sx;
sx.Create("1:10","x");
//Squaring sx, which is the same as S expression sy <- x*x in a local
frame,
//but here we set it to local C++ variable sy.
CSPnumeric sy = sx * sx;
// Assign the result as S object with name "y" in the current
database.
sy.Assign("y");
//Evaluate z<-lm(y~x)
g_engineConnect.SyncParseEval("z<-lm(y~x)");
maybe ------------------- CSPobject Eval ("z<-lm(y~x)");
//second example
CSPevaluator s;
CSPcharacter message("''hello''");
message.Print();
//CSPmatrix M("matrix(1:4,rnow=2)");
//M.Print();
*/
printf("Normal Termination\n");
return 0;
}
On Tue, 28 Oct 2008 07:07:37 -0700 (PDT), Curious wrote:
A business associate told me that I should be able to run C++ code in
C#.NET environment because C++ and C# belong to the same family.Your business associate was wrong.
Now, there is a version of C++ for the .NET framework, called C++/CLI, but
there are typical certain changes that need to be made to adapt a generic
C++ program to it.
这篇关于在C#.NET中运行C ++代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!