我有一个C ++文件I / O功能。我想在fortran的写声明中调用该函数。写入可以使用一些索引设备,如<?php
interface IConnectInfo {
const HOST = 'XXX.0.0.1:XXXX';
const UNAME = 'root';
const PW = 'xxx';
const DBNAME = 'test';
public static function doConnect();
}
class UniversalConnect implements IConnectInfo{
private static $server=IConnectInfo::HOST;
private static $currentDB=IConnectInfo::DBNAME;
private static $user=IConnectInfo::UNAME;
private static $pass=IConnectInfo::PW;
private static $hookup;
public static function doConnect() {
self::$hookup = mysqli_connect(self::$server, self::$user, self::$pass, self::$currentDB);
if(self::$hookup) {
echo ("Successful connection to MySQL:<br/>");
}
elseif (mysqli_connect_error(self::$hookup)) {
echo ('Here is what is failed: ' .mysqli_connect_error());
}
return self::$hookup;
}
}
class LiveSearch {
private $table;
private $hookup;
private $sql;
private $name = array();
private $res;
private $json;
private $term;
public function __construct() {
$this->table = "master";
//create mysqli object
$this->hookup = UniversalConnect::doConnect();
$this->doDisplay();
$this->hookup->close();
}
public function doDisplay() {
$this->term = 'g';
//$this->term = $_GET['term'];
$this->sql = "SELECT DISTINCT(Asset) FROM $this->table where Business LIKE '%$this->term%'";
try {
$result = $this->hookup->query($this->sql);
while ($row = $result->fetch_assoc()) {
$this->res = $row['Asset'];
array_push($this->name, $this->res);
}
$this->json = json_encode($this->name);
echo $this->json;
$result->close();
}
catch(Exception $e) {
echo "Here's what went wrong: " .$e->getMessage();
}
}
}
$Business1 = new LiveSearch();
?>
。我知道如何通过定义一个新函数来做到这一点。但是可以写语句调用我的函数吗?
答案 0 :(得分:3)
不要混用Fortran和C ++ I / O,这是灾难的一种方法。
在许多编译器中,甚至不允许调用从Fortran打印语句(递归I / O)执行I / O操作的Fortran函数,并且可能会停止您的程序。使用C ++函数,坏事发生的几率甚至更高。
正确的做法是仅使用其中一种语言执行I / O.例如,您可以使用C ++写入字符串,将字符串返回给Fortran并在Fortran中打印。或者相反。