Le Mardi 13 Septembre 2005 16:04, Tom Schindl a écrit :
> > Sure, but what are those "#include-directives" ? Where do I find them ?
> > What do they correspond to ?
>
> I'm not a c++ guy but I meant the header-includes you use don't you need
> any includes?

Right, I will add them.
I modified the code. Hope now it is good :-)

Cheers,
Pierre-André
-- 
StarXpert - www.starxpert.fr
e-mail : [EMAIL PROTECTED]
<?xml version="1.0"?>
<!--
$RCSfile: $
last change: $Revision: $ $Author: $ $Date: $

(c)2003 by the copyright holders listed with the author-tags.
If no explicit copyright holder is mentioned with a certain author,
the author him-/herself is the copyright holder. All rights reserved.

Public Documentation License Notice:

The contents of this Documentation are subject to the
Public Documentation License Version 1.0 (the "License");
you may only use this Documentation if you comply with
the terms of this License. A copy of the License is
available at http://www.openoffice.org/licenses/PDL.html

The Original Documentation can be found in the CVS archives
of openoffice.org at the place specified by RCSfile: in this header.

The Initial Writer(s) of the Original Documentation are listed
with the author-tags below.

The Contributor(s) are listed with the author-tags below
without the marker for being an initial author.

All Rights Reserved.
-->

<snippet language="Cpp" application="Office">

<keywords>
	<keyword>OUStrings</keyword>
	<keyword>Strings</keyword>
	<keyword>std</keyword>
	<keyword>string</keyword>
	<keyword>print</keyword>
	<keyword>&lt;&lt;</keyword>
	<keyword>cout</keyword>
</keywords>

<authors>
	<author id="pagalmes" initial="true" email="[EMAIL PROTECTED]" copyright="StarXpert">Pierre-Andr&#233; Galmes</author>
</authors>

<question heading="&apos;Cout&apos; an OUStrings ?">Howto print OUStrings ?


<p>I do want to see the content of an OUString. How do I do </p>
<p>to use the standard output to display it ?</p>
</question>

<answer>
<p>In fact, to print an OUString, you need to convert it in a OString.</p>
<p></p>
<p>The result of the code :</p>
<p></p>
<p>aouString : 0xb5b87fd8</p>
<p>aOString : Coucou</p>
<listing>/*  Copyright (C) 2005  - StarXpert */

#include &lt;iostream&gt;
#include &lt;exception&gt;
#include &lt;rtl/ustring.hxx&gt;

using namespace std;
using namespace ::rtl;


int SAL_CALL main(int argc, char **argv)
{

        OUString aouString  = OUString::createFromAscii( &quot;Coucou&quot; );
        OString   aOString  = ::rtl::OUStringToOString ( aouString,
                        RTL_TEXTENCODING_UTF8);
        cout &lt;&lt; &quot;aouString : &quot; &lt;&lt;  aouString &lt;&lt; endl;
        cout &lt;&lt; &quot;aOString : &quot;  &lt;&lt;   aOString &lt;&lt; endl;

        return 0;
}</listing>
</answer>

<versions>
	<version number="2.0.x" status="tested"/>
</versions>

<operating-systems>
<operating-system name="All"/>
</operating-systems>

<changelog>
	<change author-id="pagalmes" date="2005-09-13">Added the #include in the code</change>
	<change author-id="pagalmes" date="2005-09-13">Initial version</change>
</changelog>

</snippet>
<?xml version="1.0"?>
<!--
$RCSfile: $
last change: $Revision: $ $Author: $ $Date: $

(c)2003 by the copyright holders listed with the author-tags.
If no explicit copyright holder is mentioned with a certain author,
the author him-/herself is the copyright holder. All rights reserved.

Public Documentation License Notice:

The contents of this Documentation are subject to the
Public Documentation License Version 1.0 (the "License");
you may only use this Documentation if you comply with
the terms of this License. A copy of the License is
available at http://www.openoffice.org/licenses/PDL.html

The Original Documentation can be found in the CVS archives
of openoffice.org at the place specified by RCSfile: in this header.

The Initial Writer(s) of the Original Documentation are listed
with the author-tags below.

The Contributor(s) are listed with the author-tags below
without the marker for being an initial author.

All Rights Reserved.
-->

<snippet language="Cpp" application="Office">

<keywords>
	<keyword>Sequence</keyword>
	<keyword>Sequences</keyword>
	<keyword>c++</keyword>
	<keyword>cpp</keyword>
	<keyword>getAvailableServiceNames</keyword>
</keywords>

<authors>
	<author id="pagalmes" initial="true" email="[EMAIL PROTECTED]" copyright="StarXpert">Pierre-Andr&#233;  Galmes</author>
</authors>

<question heading="Howto acces to the content of a Sequence ?">Howto acces to the content of a Sequence ?

<p>A function returns a Sequence&lt;class T&gt;. Is there any function</p>
<p>associated with the class to acces its data ?</p>
</question>

<answer>
<p>In fact, Sequences are manipulated like array.</p>
<listing>#include &lt;iostream&gt;
#include &lt;exception&gt;
#include &lt;rtl/ustring.hxx&gt;

#include &lt;cppuhelper/bootstrap.hxx&gt;
#include &lt;com/sun/star/bridge/XUnoUrlResolver.hpp&gt;
#include &lt;com/sun/star/lang/XMultiServiceFactory.hpp&gt;

using namespace std;
using namespace ::rtl;


main()
{

[...]

// Returns a sequence of OUString.
Sequence&lt; ::rtl::OUString &gt; sq =
rxOfficeServiceManager-&gt;getAvailableServiceNames();

// Returns he number of objects in the sequence.
sq.getLength(); 

// Access the content of the sequence.
OUString a = sq[1];
OUString b = sq[801]; // sq.getLength() - 1

}</listing>
</answer>

<versions>
	<version number="2.0.x" status="tested"/>
	<version number="1.1.x" status="untested"/>
</versions>

<operating-systems>
<operating-system name="All"/>
</operating-systems>

<changelog>
	<change author-id="pagalmes" date="2005-09-13">added #include directives</change>
	<change author-id="pagalmes" date="2005-09-13">Initial version</change>
</changelog>

</snippet>
<?xml version="1.0"?>
<!--
$RCSfile: $
last change: $Revision: $ $Author: $ $Date: $

(c)2003 by the copyright holders listed with the author-tags.
If no explicit copyright holder is mentioned with a certain author,
the author him-/herself is the copyright holder. All rights reserved.

Public Documentation License Notice:

The contents of this Documentation are subject to the
Public Documentation License Version 1.0 (the "License");
you may only use this Documentation if you comply with
the terms of this License. A copy of the License is
available at http://www.openoffice.org/licenses/PDL.html

The Original Documentation can be found in the CVS archives
of openoffice.org at the place specified by RCSfile: in this header.

The Initial Writer(s) of the Original Documentation are listed
with the author-tags below.

The Contributor(s) are listed with the author-tags below
without the marker for being an initial author.

All Rights Reserved.
-->

<snippet language="Cpp" application="Office">

<keywords>
	<keyword>Sequence</keyword>
	<keyword>Sequences</keyword>
	<keyword>iterate</keyword>
	<keyword>iteration</keyword>
</keywords>

<authors>
	<author id="pagalmes" initial="true" email="[EMAIL PROTECTED]" copyright="StarXpert">Pierre-Andr&#233; Galmes</author>
</authors>

<question heading="Iterate over a Sequence">Howto iterate over a Sequence ?
</question>

<answer>
<p>Use the following routine :</p>
<listing>#include &lt;iostream&gt;
#include &lt;exception&gt;
#include &lt;rtl/ustring.hxx&gt;

#include &lt;cppuhelper/bootstrap.hxx&gt;
#include &lt;com/sun/star/bridge/XUnoUrlResolver.hpp&gt;
#include &lt;com/sun/star/lang/XMultiServiceFactory.hpp&gt;

using namespace std;
using namespace ::rtl;


main()
{

[...]

// Get a sequence.
Sequence&lt; ::rtl::OUString &gt; sq = 
rxOfficeServiceManager-&gt;getAvailableServiceNames();

// Set some variables on the beginning and the end of the sequence.
rtl::OString aOString;
const ::rtl::OUString* sIterator = sq.getConstArray();
const ::rtl::OUString* sEnd = sIterator + sq.getLength();

// Iterate and display the result.
for ( ; sIterator != sEnd ; ++sIterator)
{
        aOString = ::rtl::OUStringToOString ( *sIterator, RTL_TEXTENCODING_UTF8 );
        cout &lt;&lt; &quot;sq : &quot; &lt;&lt;  aOString &lt;&lt; endl;
}

}</listing>
</answer>

<versions>
	<version number="2.0.x" status="tested"/>
</versions>

<operating-systems>
<operating-system name="All"/>
</operating-systems>

<changelog>
	<change author-id="pagalmes" date="2005-09-13">Initial version</change>
</changelog>

</snippet>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to