Re: ostream, istream, and String^
- From: "Peteroid" <peter_oliphant@xxxxxxx>
- Date: Thu, 15 Dec 2005 16:45:19 -0800
> Would you care to explain which error you see?
The ones I indicated, both of which are something like 'no overload of '<<'
or '>>' exists for String^".
>> I don't know what you're trying to achive, but the
>> implementation looks quite pointless.
Let me expalin it to you with code that does work. This code does work:
>> ostream% operator <<( ostream% output, int value)
>> {
>> output << value ; //ok
>> return output ;
>> }
This takes the output stream given as a parameter, uses ITS '<<' operator
for 'int' and adds 'value' to the stream, and then returns the resulting
stream. This is the standard way of doing streaming, such as when saving
values serially to a file.
>>the implementations recursively call themselves.
The '<<' used in the implementation of the method is not the same '<<' this
method defines.
So my problem is because String^ does not have a natural overload of '<<'
which is used to add it to streams. THAT is what I need, is a way to
send/recieve String^'s through a stream (both directions). I'm guessing part
of the problem is that String^ are both variable in length and mutable...
[==P==]
"Holger Grund" <holger.grund@xxxxxxxxxxxxxxx> wrote in message
news:OBWTccdAGHA.3048@xxxxxxxxxxxxxxxxxxxxxxx
> "Peteroid" <peter_oliphant@xxxxxxx> wrote
>>I switched this entirely to the new syntax, so this is the question now:
>>
>> ostream% operator <<( ostream% output, String^ str )
>> {
>> output << str ; //compile error
>> return output ;
>> }
>>
>>
>> istream% operator >>( istream% input, String^ str )
>> {
>> input >> str ; // compile error
>> return input ;
>> }
>>
> Would you care to explain which error you see? I don't see anything wrong
> with the above syntax. I don't know what you're trying to achive, but the
> implementation looks quite pointless. Unless ADL finds an overload with
> the same signature in another namespace (in which case the operators
> will be ambigious), the implementations recursively call themselves.
>
> You'll probably want something along the lines of
> ostream% operator<<( ostream% output, String^ str)
> {
> pin_ptr<const unsigned char> s =
> &System::Text::Encoding::ASCII->GetBytes( str )[0];
>
> return
> output << static_cast<const char*>(static_cast<const void*>(s));
> }
>
> The second signature does not make sense. Strings are immutable. You
> won't get anything. The signature should look like
>
> istream% operator >>( istream% input, String^% str )
> {
> std::string s;
> input >> s;
> str = gcnew String( s.c_str() );
> }
>
> -hg
>
.
- Follow-Ups:
- Re: ostream, istream, and String^
- From: Holger Grund
- Re: ostream, istream, and String^
- References:
- ostream, istream, and String^
- From: Peteroid
- Re: ostream, istream, and String^
- From: Peteroid
- Re: ostream, istream, and String^
- From: Holger Grund
- ostream, istream, and String^
- Prev by Date: Re: ostream, istream, and String^
- Next by Date: Re: ostream, istream, and String^
- Previous by thread: Re: ostream, istream, and String^
- Next by thread: Re: ostream, istream, and String^
- Index(es):
Relevant Pages
|