OO-Snippets: 'Cout' an OUStrings ?

Commons

KeywordsOUStrings, Strings, std, string, print, <<, cout
LanguageCpp
ApplicationOffice
AuthorsPierre-André Galmes (initial)
Supported Versions2.0.x  
Supported OSAll  
QuestionHowto print OUStrings ?

I do want to see the content of an OUString. How do I do

to use the standard output to display it ?

Answer

In fact, to print an OUString, you need to convert it in a OString.

The result of the code :

aouString : 0xb5b87fd8

aOString : Coucou

Code-Snippet-Listing (snippet-source)

/*  Copyright (C) 2005  - StarXpert - http://www.starxpert.fr */

#include <iostream>
#include <exception>
#include <rtl/ustring.hxx>

using namespace std;
using namespace ::rtl;


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

        OUString aouString  = OUString::createFromAscii( "Coucou" );
        OString   aOString  = ::rtl::OUStringToOString ( aouString,
                        RTL_TEXTENCODING_UTF8);
        cout << "aouString : " <<  aouString << endl;
        cout << "aOString : "  <<   aOString << endl;

        return 0;
}

Changelog

DateUserModification
2005-09-13pagalmesAdded the #include in the code
2005-09-13pagalmesInitial version

and