Re: ostream, istream, and String^

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



> 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
>


.



Relevant Pages

  • Re: sql xml bulkload error
    ... I agree there should be an overload for it - maybe I'm looking in the wrong ... You can load your XML string into the stream ... > load much, so there may not be an overload, but that is where I would look. ...
    (microsoft.public.dotnet.general)
  • Re: Question about design, defmacro, macrolet, and &environment
    ... "Expects to find the literal string on the stream." ... (defun send (string &optional stream) ... (declaim (inline make-adjustable-string)) ...
    (comp.lang.lisp)
  • Re: Strange problem when not in debugger
    ... private string huidigWeb; ... int buffLength = 2048; ... // Opens a file stream to read the file to be uploaded ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: ReplacerStream
    ... string, do a replace on that string and create a stream again to be ... If those are problems, and you are looking just for a single string, it seems to me that you could just read the stream one character at a time, checking to see if it matches the current character in your search string. ...
    (microsoft.public.dotnet.framework)
  • Re: Strange problem when not in debugger
    ... private string huidigWeb; ... int buffLength = 2048; ... // Opens a file stream to read the file to be uploaded ...
    (microsoft.public.dotnet.languages.csharp)