Path: news.mathworks.com!not-for-mail
From: "Siva Mettupalayam" <siva@colorado.edu>
Newsgroups: comp.soft-sys.matlab
Subject: C++ mex question
Date: Mon, 1 Sep 2008 01:26:02 +0000 (UTC)
Organization: University of Colorado at Boulder
Lines: 37
Message-ID: <g9fgba$bs0$1@fred.mathworks.com>
Reply-To: "Siva Mettupalayam" <siva@colorado.edu>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1220232362 12160 172.30.248.38 (1 Sep 2008 01:26:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 1 Sep 2008 01:26:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1038946
Xref: news.mathworks.com comp.soft-sys.matlab:488051



Hi,

I am using Matlab R2008a 64 bit and MSVC++ 9.0 (Visual 
Studio 2008) on Windows Vista 64 bit. I compile the 
following mex function

#include "mex.h"
#include <iostream>
using namespace std;

extern "C"
void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const 
mxArray *prhs[])
{
    cout << "Test" << endl << flush;
    //printf("Test\n");
}

The cout doesn't result in anything being displayed.

Section 26 of the tech note 
http://www.mathworks.com/support/tech-notes/1600/1605.html

does say "Using cout will not work as expected in C++ MEX-
files. This is because cout is expecting to use a display 
that is not MATLAB. To workaround this problem, use 
mexPrintf instead.". However,
1. This mex function works with Matlab R14 and MSVC++ 7.1 
(Visual Studio 2003) on Windows XP. 
2. I am using some C++ template libraries that use cout. So 
I cannot change them to mexPrintf.
3. The commented printf call works. Aren't cout and printf 
using the same output device?

Thank you for your help.

Siva