MATLAB Answers


Is it possible to use C++ string and sstream in MATLAB MEX?

Asked by AP
on 19 Feb 2013

Dear All,

Is it possible to use C++ string and sstream in a MATLAB MEX file? The following is a part of my code in which I am having problem:

string VariableNames;
ostringstream strout( VariableNames );
strout << "x y z "; 
for( int i = 0; i<N; i++)		
	strout << GetComponentName( i ) << " ";		
VariableNames = strout.str();

Although I have included string and sstream header files, MATLAB complains with the following error message:

 error C2065: 'string' : undeclared identifier

Could someone tell me if using C++ string is usable in MEX.




You probably also need to add "using namespace std;", and ensure that your MEX-file has a .cpp extension.

Thanks @Kaustubha. Excellent catch. namespace was the problem.

Log in to comment.



0 Answers

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!