Hi,
I'm trying to use stringstreams in a tuple like
fstream fin(filename.c_str(), ios_base::in);
tuple
CodeLogic wrote:
Hi,
Hi, Let me reorder your message a bit.
I'm trying to use stringstreams in a tuple like
... give me the following error:
c:\.....\include\boost-1_32\boost\tuple\detail\tuple_basic_no_partial_spec.hpp(1 90):
error C2558: class 'std::basic_stringstream<_Elem,_Traits,_Alloc>' : no copy constructor available or copy constructor is declared 'explicit' with [ _Elem=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char> ]
You can't create a tuple of stringstreams because basic_ios, which is a base class of stringstream, is non copyable. You should be able to create a tuple of references to stringstreams, though.
fstream fin(filename.c_str(), ios_base::in); tuple
test; fin>>test;
It's not clear what you're trying to do do here. If I saw this code in isolation, I'd guess you were trying to deserialize a tuple containing three strings.
I'm basically looking for a solution of being able to stream tuples with strings in the them in and out of a file.> Any suggestions will be appreciated.
Do you mean you want to store and retrieve a tuple
Thanks !
Jonathan
Jonathan Turkanis wrote:
fstream fin(filename.c_str(), ios_base::in); tuple
test; fin>>test; It's not clear what you're trying to do do here. If I saw this code in isolation, I'd guess you were trying to deserialize a tuple containing three strings.
I meant three stringstreams. Jonathan
Jonathan Turkanis wrote:
Jonathan Turkanis wrote:
fstream fin(filename.c_str(), ios_base::in); tuple
test; fin>>test; It's not clear what you're trying to do do here. If I saw this code in isolation, I'd guess you were trying to deserialize a tuple containing three strings.
I meant three stringstreams.
Oy! I meant four stringstreams. I guess I should go back to sleep.
Jonathan
You can't create a tuple of stringstreams because basic_ios, which is a base class of stringstream, is non copyable. You should be able to create a tuple of references to stringstreams, though.
I see, my intention is to create tuples consisting of strings (strings or stringstream is immaterial for me, I used stringstream since they support io streams and I thought they would be more compatible when streaming tuples) and basically have the capability of streaming it in and out of a file.
fstream fin(filename.c_str(), ios_base::in); tuple
test; fin>>test; It's not clear what you're trying to do do here. If I saw this code in isolation, I'd guess you were trying to deserialize a tuple containing three strings.
This is my attempt of streaming a tuple from a file into the data struct. Maybe my code is incorrect :) ?
Do you mean you want to store and retrieve a tuple
? You can't use operator>> for this, since it will use whitespace as a separator, in addition to being sensitive to istream field widths.
If the whitespace factor is the only drawback, I can work around it by replacing whitespaces (which I actually doubt I will have in my strings) with some other character like an '_'. If there are no whitespaces should this work as expected?
You might try Boost.Serialization, although since I haven't used this library yet I don't know whether there is support for serializing tuples or whether you have to do it yourself. A simpler way would simply be to write the string to a file separated by a character which you know won't appear in any of the strings, if there is such a character.
From what I read in the tuples documentation, tuples supports streaming out of the box: http://www.boost.org/libs/tuple/doc/tuple_users_guide.html#streaming I figured as long as I use fields that themselves supports streams (like stringstream), it should work fine. But however, in the end, what I need is the ability to save tuples (consisting of strings and assuming there are no white spaces within each string) into a file and reload it when necessary. Thanks a lot for your response ! CodeLogic.
participants (2)
-
CodeLogic
-
Jonathan Turkanis