⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 structarraycreate.cpp

📁 《精通matlab与c++混合编程》的光盘内容
💻 CPP
字号:
// structArrayCreate.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include "matlab.hpp"
#include <stdlib.h>    

#ifdef GCC
 #ifndef EXIT_SUCCESS
  #define EXIT_SUCCESS 0
 #endif
#endif


int main(int argc, char* argv[])
{
	/*构建MATLAB结构阵列*/
	mwArray sA;
	sA = struct_func("Name","Daniel",
					 "Phone",888888,
					 "Address","北京市外国语学院");/*结构体域名  结构体域值*/

	/*采用cell2struct转换函数构建结构阵列*/	
	/*MATLAB语句*/
	/*
		sB = {'Daniel',888888,'北京市外国语学院');
		sC = {'Name','Phone','Address');
		sD = cell2struct(sB,sC,2);
	*/
	mwArray sB,sC,sD;
	sB = cellhcat("Daniel",888888,"北京市外国语学院");
	sC = cellhcat("Name","Phone","Address");
	sD = cell2struct(sB,sC,2);/*注意2*/
	
	/*MATLAB语句*/
	/*
		sB = {'Daniel';888888;'北京市外国语学院');
		sC = {'Name','Phone','Address');
		sD = cell2struct(sB,sC,1);
	*/
	sB = vertcat(cellhcat("Daniel"),cellhcat(888888),cellhcat("北京市外国语学院"));
	sC = cellhcat("Name","Phone","Address");
	sD = cell2struct(sB,sC,1);/*注意1*/
	
	cout << "采用struct_fucn函数构建结构:\n"<<sA<<endl;
	cout << "采用cell2struct转换函数构建结构:\n"<<sD<<endl;	

	char str[30];	
	cout << "请输入需要查询的域名:\n"<<endl;
	cin >> str;
	mwArray is = isfield(sD,str);	
	if(tobool(is))/*tobool用于将mwArray 布尔变量转换为 c++布尔变量*/
	{
		cout << "输入域名在结构体sD中存在!\n"<<endl;
	}	
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -