You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openoffice.apache.org by jorge ivan poot diaz <iv...@gmail.com> on 2013/04/17 01:46:32 UTC

std::stringstream aStrStream

Hello,

I am modifying this code in AOO:
http://opengrok.adfinis-sygroup.org/source/xref/aoo-trunk/main/cui/source/tabpages/tpcolor.cxx#465

I'm trying to concatenate with stringstream but I have errors when I'am
building:

1- I already included:
#include <sstream>

2- I have added the following code:
http://imagebin.org/254288

3- This is the error:
http://imagebin.org/254289

Help me, regards!!

Re: std::stringstream aStrStream

Posted by jorge ivan poot diaz <iv...@gmail.com>.
Hello all,

http://www.openoffice.org/api/docs/cpp/ref/names/rtl/OString/o.htm

OString* OString*( const
OString<http://www.openoffice.org/api/docs/cpp/ref/names/rtl/c-OString.html>&
str ) throw();
Summary: New string from OString.

------------------------------------------------------------------------------

I found this fragment of code (above), it is interesting, I want to know if
there is a function to STRING.







2013/4/20 Ariel Constenla-Haile <ar...@apache.org>

> On Fri, Apr 19, 2013 at 11:59:41AM -0500, jorge ivan poot diaz wrote:
> >  std::stringstream aS;
> [...]
> > std::string s = aS.str();
> [...]
> >         pEntry = new XColorEntry( aAktuellColor, s );
> > <----------------------
> > Would be like this
> >
> >         pColorTab->Insert( pColorTab->Count(), pEntry );
> >
> >         aLbColor.Append( pEntry );
> >         aValSetColorTable.InsertItem( aValSetColorTable.GetItemCount() +
> 1,
> >                 pEntry->GetColor(), pEntry->GetName() );
> >
> >         aLbColor.SelectEntryPos( aLbColor.GetEntryCount() - 1 );
> >
> > But this does not work, in building generates error:
> > http://imagebin.org/254616
>
> (it would be more useful to put the error in a pastebin, not an
> imagebin)
>
> The error message is rather clear: there is no matching function call to
> the any of the constructors of XColorEntry, none takes a std::string.
>
>
> http://opengrok.adfinis-sygroup.org/source/xref/aoo-trunk/main/svx/inc/svx/xtable.hxx#57
>
> The constructor that is used in this code is
>
> XColorEntry(const Color& rColor, const String& rName)
>
> it takes a tools' string
>
> http://opengrok.adfinis-sygroup.org/source/xref/aoo-trunk/main/tools/inc/tools/string.hxx
>
>
> On the other head, why are you using std::stringstream/string?  In the
> core code you should not use standard C++ string classes, but
> rtl::OUString, OUStringBuffer, etc.; even if you are playing with the
> code, before diving into the source, you should get familiar with them
> - in general, with the whole C++ UNO language binding:
>
>
> http://wiki.openoffice.org/wiki/Documentation/DevGuide/ProUNO/C%2B%2B/C%2B%2B_Language_Binding
> http://www.openoffice.org/api/docs/cpp/ref/
> http://www.openoffice.org/api/docs/cpp/ref/names/rtl/c-OUString.html
> http://www.openoffice.org/api/docs/cpp/ref/names/rtl/c-OString.html
> http://www.openoffice.org/api/docs/cpp/ref/names/rtl/c-OUStringBuffer.html
> http://www.openoffice.org/api/docs/cpp/ref/names/rtl/c-OStringBuffer.html
>
> Set-up the SDK and play with the string sample in
>
> http://svn.apache.org/viewvc/openoffice/trunk/main/odk/examples/DevelopersGuide/ProfUNO/CppBinding/
>
>
> Regards
> --
> Ariel Constenla-Haile
> La Plata, Argentina
>

Re: std::stringstream aStrStream

Posted by Ariel Constenla-Haile <ar...@apache.org>.
On Fri, Apr 19, 2013 at 11:59:41AM -0500, jorge ivan poot diaz wrote:
>  std::stringstream aS;
[...]
> std::string s = aS.str();
[...]
>         pEntry = new XColorEntry( aAktuellColor, s );
> <----------------------
> Would be like this
> 
>         pColorTab->Insert( pColorTab->Count(), pEntry );
> 
>         aLbColor.Append( pEntry );
>         aValSetColorTable.InsertItem( aValSetColorTable.GetItemCount() + 1,
>                 pEntry->GetColor(), pEntry->GetName() );
> 
>         aLbColor.SelectEntryPos( aLbColor.GetEntryCount() - 1 );
> 
> But this does not work, in building generates error:
> http://imagebin.org/254616

(it would be more useful to put the error in a pastebin, not an
imagebin)

The error message is rather clear: there is no matching function call to
the any of the constructors of XColorEntry, none takes a std::string.

http://opengrok.adfinis-sygroup.org/source/xref/aoo-trunk/main/svx/inc/svx/xtable.hxx#57

The constructor that is used in this code is

XColorEntry(const Color& rColor, const String& rName)

it takes a tools' string
http://opengrok.adfinis-sygroup.org/source/xref/aoo-trunk/main/tools/inc/tools/string.hxx


On the other head, why are you using std::stringstream/string?  In the
core code you should not use standard C++ string classes, but
rtl::OUString, OUStringBuffer, etc.; even if you are playing with the
code, before diving into the source, you should get familiar with them
- in general, with the whole C++ UNO language binding:

http://wiki.openoffice.org/wiki/Documentation/DevGuide/ProUNO/C%2B%2B/C%2B%2B_Language_Binding
http://www.openoffice.org/api/docs/cpp/ref/
http://www.openoffice.org/api/docs/cpp/ref/names/rtl/c-OUString.html
http://www.openoffice.org/api/docs/cpp/ref/names/rtl/c-OString.html
http://www.openoffice.org/api/docs/cpp/ref/names/rtl/c-OUStringBuffer.html
http://www.openoffice.org/api/docs/cpp/ref/names/rtl/c-OStringBuffer.html

Set-up the SDK and play with the string sample in
http://svn.apache.org/viewvc/openoffice/trunk/main/odk/examples/DevelopersGuide/ProfUNO/CppBinding/


Regards
-- 
Ariel Constenla-Haile
La Plata, Argentina

Re: std::stringstream aStrStream

Posted by jorge ivan poot diaz <iv...@gmail.com>.
I implemented the code, thanks.

At the beginning of the class I put this code:

Original Code
String aName( aEdtName.GetText() );

I've replaced with
::rtl::OUString aName2( aEdtName.GetText() );

The concatenation. This is fine

 std::stringstream aS;
            aS <<
                 "This"
                 << ::rtl::OUStringToOString(aName2,
RTL_TEXTENCODING_ASCII_US).getStr()
                 << std::endl;

I convert from stringstream to string

std::string s = aS.str();
        _STL::cout << s;

Now I want to replace aName with s, in the following code fragment:

if (eCM != CM_RGB)

            ConvertColorValues (aAktuellColor, CM_RGB);
        pEntry = new XColorEntry( aAktuellColor, aName );
<---------------------- Original code
        pEntry = new XColorEntry( aAktuellColor, s );
<----------------------
Would be like this

        pColorTab->Insert( pColorTab->Count(), pEntry );

        aLbColor.Append( pEntry );
        aValSetColorTable.InsertItem( aValSetColorTable.GetItemCount() + 1,
                pEntry->GetColor(), pEntry->GetName() );

        aLbColor.SelectEntryPos( aLbColor.GetEntryCount() - 1 );

But this does not work, in building generates error:
http://imagebin.org/254616

It could be the type of variable?
How is the conversion from stringstream to string, is ok?


2013/4/18 Andre Fischer <aw...@gmail.com>

> On 18.04.2013 04:51, jorge ivan poot diaz wrote:
>
>> Hello,
>>
>> Thanks you,  I have already changed the string as you said me. This is the
>> result:
>> ::rtl::OUString aName ( aEdtName.GetText() );
>>
>> And then I put this code
>>
>> std::stringstream aStrStream;
>>              aStrStream << "\nThis is " << aName << " and " << aName << "
>> genial!" <<std::endl;
>>              _STL::cout << aStrStream.str();
>>
>> The building was successful, but does not print whole aStrStream. Only
>> this
>> part:
>> This is
>> http://imagebin.org/254440
>>
>
> OUString is a UTF-16 string.  That means that when it is created from an
> ASCII string then every second byte is '\0'.  That means that
>
>             aStrStream << "\nThis is " << aName << ...
>
> is basically equivalent to
>
>             aStrStream << "\nThis is " << '\0' << ...
>
> Therfore everything after "\nThis is " is cut off.  To fix this you have
> to replace
>     << aName <<
>
> with
>
>   << ::rtl::OUStringToOString(**aName, RTL_TEXTENCODING_ASCII_US).**getStr()
> <<
>
> You may want to use a small method to make this more readable:
>
>   namespace
>   {
>       sal_Char* o2a (const ::rtl::OUString& rsText)
>      {
>       return ::rtl::OUStringToOString(**rsText,
> RTL_TEXTENCODING_ASCII_US).**getStr();
>      }
>   }
>
> and then
>
>     aStrStream << "\nThis is " << o2a(aName) << ...
>
> [I did not compile this, there may be typos in this]
>
>
>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: dev-unsubscribe@openoffice.**apache.org<de...@openoffice.apache.org>
> For additional commands, e-mail: dev-help@openoffice.apache.org
>
>

Re: std::stringstream aStrStream

Posted by Andre Fischer <aw...@gmail.com>.
On 18.04.2013 04:51, jorge ivan poot diaz wrote:
> Hello,
> Thanks you,  I have already changed the string as you said me. This is the
> result:
> ::rtl::OUString aName ( aEdtName.GetText() );
>
> And then I put this code
>
> std::stringstream aStrStream;
>              aStrStream << "\nThis is " << aName << " and " << aName << "
> genial!" <<std::endl;
>              _STL::cout << aStrStream.str();
>
> The building was successful, but does not print whole aStrStream. Only this
> part:
> This is
> http://imagebin.org/254440

OUString is a UTF-16 string.  That means that when it is created from an 
ASCII string then every second byte is '\0'.  That means that

             aStrStream << "\nThis is " << aName << ...

is basically equivalent to

             aStrStream << "\nThis is " << '\0' << ...

Therfore everything after "\nThis is " is cut off.  To fix this you have to replace
   
   << aName <<

with

   << ::rtl::OUStringToOString(aName, RTL_TEXTENCODING_ASCII_US).getStr() <<

You may want to use a small method to make this more readable:

   namespace
   {
       sal_Char* o2a (const ::rtl::OUString& rsText)
      {
       return ::rtl::OUStringToOString(rsText, 
RTL_TEXTENCODING_ASCII_US).getStr();
      }
   }

and then

     aStrStream << "\nThis is " << o2a(aName) << ...

[I did not compile this, there may be typos in this]



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@openoffice.apache.org
For additional commands, e-mail: dev-help@openoffice.apache.org


Re: std::stringstream aStrStream

Posted by jorge ivan poot diaz <iv...@gmail.com>.
Hello,
Thanks you,  I have already changed the string as you said me. This is the
result:
::rtl::OUString aName ( aEdtName.GetText() );

And then I put this code

std::stringstream aStrStream;
            aStrStream << "\nThis is " << aName << " and " << aName << "
genial!" <<std::endl;
            _STL::cout << aStrStream.str();

The building was successful, but does not print whole aStrStream. Only this
part:
This is
http://imagebin.org/254440

What causes this?
Could be some error in the code or in the concatenation?




2013/4/17 Andre Fischer <aw...@gmail.com>

> On 17.04.2013 17:09, jorge ivan poot diaz wrote:
>
>> I don't see a definition of aName, but from the error message assume that
>>>
>> it is String.
>> http://imagebin.org/254354
>>
>>  That is because the String class has no << operator defined. Try to use
>>>
>> aName.getStr() instead of just aName.
>> http://imagebin.org/254355
>>
>> As you can see from the picture, I already made the change, but I have the
>> following error:
>> http://imagebin.org/254357
>>
>> I try with aEdtName.GetText () instead of aName.getStr() but yet does not
>> compile:
>> http://imagebin.org/254361
>>
>> Help, ragards.
>>
>
> Sorry, I do not use String anymore and had to guess and apparently guessed
> wrong.  If you can, you probably should use ::rtl::OUString instead of
> String.  The conversion to char* looks like this:
>   ::rtl::OUString sText (::rtl::OUString::**createFromAscii("some text"));
>   ::std::cout << ::rtl::OUStringToOString(**sText,
> RTL_TEXTENCODING_ASCII_US).**getStr() << ::std::endl;
> or something very similar to this.
>
> If you still want to use String then cosv/inc/cosv/string.hxx suggests to
> use c_str() to obtain a char*.
>
> -Andre
>
>
>>
>>
>>
>> 2013/4/17 Andre Fischer <aw...@gmail.com>
>>
>>  On 17.04.2013 01:46, jorge ivan poot diaz wrote:
>>>
>>>  Hello,
>>>>
>>>> I am modifying this code in AOO:
>>>> http://opengrok.adfinis-**sygr**oup.org/source/xref/aoo-**<http://sygroup.org/source/xref/aoo-**>
>>>> trunk/main/cui/source/****tabpages/tpcolor.cxx#465<http:**
>>>> //opengrok.adfinis-sygroup.**org/source/xref/aoo-trunk/**
>>>> main/cui/source/tabpages/**tpcolor.cxx#465<http://opengrok.adfinis-sygroup.org/source/xref/aoo-trunk/main/cui/source/tabpages/tpcolor.cxx#465>
>>>> >
>>>>
>>>>
>>>> I'm trying to concatenate with stringstream but I have errors when I'am
>>>> building:
>>>>
>>>> 1- I already included:
>>>> #include <sstream>
>>>>
>>>> 2- I have added the following code:
>>>> http://imagebin.org/254288
>>>>
>>>>  I don't see a definition of aName, but from the error message assume
>>> that
>>> it is String.
>>>
>>>
>>>
>>>  3- This is the error:
>>>> http://imagebin.org/254289
>>>>
>>>>  That is because the String class has no << operator defined. Try to use
>>> aName.getStr() instead of just aName.
>>>
>>> -Andre
>>>
>>>
>>>  Help me, regards!!
>>>>
>>>>
>>>>  ------------------------------****----------------------------**
>>> --**---------
>>> To unsubscribe, e-mail: dev-unsubscribe@openoffice.**a**pache.org<http://apache.org>
>>> <de...@openoffice.apache.org>
>>> >
>>>
>>> For additional commands, e-mail: dev-help@openoffice.apache.org
>>>
>>>
>>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: dev-unsubscribe@openoffice.**apache.org<de...@openoffice.apache.org>
> For additional commands, e-mail: dev-help@openoffice.apache.org
>
>

Re: std::stringstream aStrStream

Posted by Andre Fischer <aw...@gmail.com>.
On 17.04.2013 17:09, jorge ivan poot diaz wrote:
>> I don't see a definition of aName, but from the error message assume that
> it is String.
> http://imagebin.org/254354
>
>> That is because the String class has no << operator defined. Try to use
> aName.getStr() instead of just aName.
> http://imagebin.org/254355
>
> As you can see from the picture, I already made the change, but I have the
> following error:
> http://imagebin.org/254357
>
> I try with aEdtName.GetText () instead of aName.getStr() but yet does not
> compile:
> http://imagebin.org/254361
>
> Help, ragards.

Sorry, I do not use String anymore and had to guess and apparently 
guessed wrong.  If you can, you probably should use ::rtl::OUString 
instead of String.  The conversion to char* looks like this:
   ::rtl::OUString sText (::rtl::OUString::createFromAscii("some text"));
   ::std::cout << ::rtl::OUStringToOString(sText, 
RTL_TEXTENCODING_ASCII_US).getStr() << ::std::endl;
or something very similar to this.

If you still want to use String then cosv/inc/cosv/string.hxx suggests 
to use c_str() to obtain a char*.

-Andre

>
>
>
>
> 2013/4/17 Andre Fischer <aw...@gmail.com>
>
>> On 17.04.2013 01:46, jorge ivan poot diaz wrote:
>>
>>> Hello,
>>>
>>> I am modifying this code in AOO:
>>> http://opengrok.adfinis-**sygroup.org/source/xref/aoo-**
>>> trunk/main/cui/source/**tabpages/tpcolor.cxx#465<http://opengrok.adfinis-sygroup.org/source/xref/aoo-trunk/main/cui/source/tabpages/tpcolor.cxx#465>
>>>
>>> I'm trying to concatenate with stringstream but I have errors when I'am
>>> building:
>>>
>>> 1- I already included:
>>> #include <sstream>
>>>
>>> 2- I have added the following code:
>>> http://imagebin.org/254288
>>>
>> I don't see a definition of aName, but from the error message assume that
>> it is String.
>>
>>
>>
>>> 3- This is the error:
>>> http://imagebin.org/254289
>>>
>> That is because the String class has no << operator defined. Try to use
>> aName.getStr() instead of just aName.
>>
>> -Andre
>>
>>
>>> Help me, regards!!
>>>
>>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: dev-unsubscribe@openoffice.**apache.org<de...@openoffice.apache.org>
>> For additional commands, e-mail: dev-help@openoffice.apache.org
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@openoffice.apache.org
For additional commands, e-mail: dev-help@openoffice.apache.org


Re: std::stringstream aStrStream

Posted by jorge ivan poot diaz <iv...@gmail.com>.
> I don't see a definition of aName, but from the error message assume that
it is String.
http://imagebin.org/254354

> That is because the String class has no << operator defined. Try to use
aName.getStr() instead of just aName.
http://imagebin.org/254355

As you can see from the picture, I already made the change, but I have the
following error:
http://imagebin.org/254357

I try with aEdtName.GetText () instead of aName.getStr() but yet does not
compile:
http://imagebin.org/254361

Help, ragards.




2013/4/17 Andre Fischer <aw...@gmail.com>

> On 17.04.2013 01:46, jorge ivan poot diaz wrote:
>
>> Hello,
>>
>> I am modifying this code in AOO:
>> http://opengrok.adfinis-**sygroup.org/source/xref/aoo-**
>> trunk/main/cui/source/**tabpages/tpcolor.cxx#465<http://opengrok.adfinis-sygroup.org/source/xref/aoo-trunk/main/cui/source/tabpages/tpcolor.cxx#465>
>>
>> I'm trying to concatenate with stringstream but I have errors when I'am
>> building:
>>
>> 1- I already included:
>> #include <sstream>
>>
>> 2- I have added the following code:
>> http://imagebin.org/254288
>>
>
> I don't see a definition of aName, but from the error message assume that
> it is String.
>
>
>
>> 3- This is the error:
>> http://imagebin.org/254289
>>
>
> That is because the String class has no << operator defined. Try to use
> aName.getStr() instead of just aName.
>
> -Andre
>
>
>> Help me, regards!!
>>
>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: dev-unsubscribe@openoffice.**apache.org<de...@openoffice.apache.org>
> For additional commands, e-mail: dev-help@openoffice.apache.org
>
>

Re: std::stringstream aStrStream

Posted by Andre Fischer <aw...@gmail.com>.
On 17.04.2013 01:46, jorge ivan poot diaz wrote:
> Hello,
>
> I am modifying this code in AOO:
> http://opengrok.adfinis-sygroup.org/source/xref/aoo-trunk/main/cui/source/tabpages/tpcolor.cxx#465
>
> I'm trying to concatenate with stringstream but I have errors when I'am
> building:
>
> 1- I already included:
> #include <sstream>
>
> 2- I have added the following code:
> http://imagebin.org/254288

I don't see a definition of aName, but from the error message assume 
that it is String.

>
> 3- This is the error:
> http://imagebin.org/254289

That is because the String class has no << operator defined. Try to use 
aName.getStr() instead of just aName.

-Andre

>
> Help me, regards!!
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@openoffice.apache.org
For additional commands, e-mail: dev-help@openoffice.apache.org