473,396 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

vector of ostringstream

Is it possible to use vector<ostringstream> ?

Here is what I have got.

===========================================
Windows 2000
CYGWIN_NT-5.0 1.3.22(0.78/3/2)
GNU gcc version 3.2 20020927 (prerelease)
===========================================

// File t.cpp
--------- C++ code : BEGIN ---------
#include <vector>
#include <sstream>
#include <iostream>
using namespace std;

int main ()
{
vector<ostringstream> oss;

oss.push_back (ostringstream()); // Line#10
oss.front() << "ABCD" << endl;

cout << oss.front().str();

return 0;
}
--------- C++ code : END -----------
--------- Compilation : BEGIN ---------

$ g++ t.cpp

/usr/include/c++/3.2/bits/ios_base.h: In copy constructor `std::basic_ios<char,
std::char_traits<char> >::basic_ios(const std::basic_ios<char,
std::char_traits<char> >&)':
/usr/include/c++/3.2/bits/stl_construct.h:78: instantiated from `void std::_Construct(_T1*, const _T2&) [with _T1 =
std::ostringstream, _T2 = std::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >]'
/usr/include/c++/3.2/bits/stl_vector.h:492: instantiated from `void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp =
std::ostringstream, _Alloc = std::allocator<std::ostringstream>]'
t.cpp:10: instantiated from here
/usr/include/c++/3.2/bits/ios_base.h:421: `std::ios_base::ios_base(const
std::ios_base&)' is private
/usr/include/c++/3.2/bits/stl_construct.h:78: within this context
/usr/include/c++/3.2/streambuf: In copy constructor `std::basic_stringbuf<char,
std::char_traits<char>, std::allocator<char> >::basic_stringbuf(const
std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char>
&)': /usr/include/c++/3.2/streambuf:486: `std::basic_streambuf<_CharT,
_Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&)
[with _CharT = char, _Traits = std::char_traits<char>]' is private
/usr/include/c++/3.2/bits/stl_construct.h:78: within this context
/usr/include/c++/3.2/bits/ios_base.h: In member function `std::basic_ios<char,
std::char_traits<char> >& std::basic_ios<char, std::char_traits<char>::operator=(const std::basic_ios<char, std::char_traits<char> >&)': /usr/include/c++/3.2/bits/stl_vector.h:893: instantiated from `void std::vector<_Tp,
_Alloc>::_M_insert_aux(__gnu_cxx::__normal_iterato r<_Tp*, std::vector<_Tp, _Alloc> >, const _Tp&) [with _Tp = std::ostringstream,
_Alloc = std::allocator<std::ostringstream>]'
/usr/include/c++/3.2/bits/stl_vector.h:496: instantiated from `void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp =
std::ostringstream, _Alloc = std::allocator<std::ostringstream>]'
t.cpp:10: instantiated from here
/usr/include/c++/3.2/bits/ios_base.h:424: `std::ios_base&
std::ios_base::operator=(const std::ios_base&)' is private
/usr/include/c++/3.2/bits/stl_vector.h:893: within this context
/usr/include/c++/3.2/streambuf: In member function `std::basic_stringbuf<char,
std::char_traits<char>, std::allocator<char> >& std::basic_stringbuf<char,
std::char_traits<char>, std::allocator<char> >::operator=(const
std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char>&)':

/usr/include/c++/3.2/streambuf:489: `std::basic_streambuf<_CharT, _Traits>&
std::basic_streambuf<_CharT, _Traits>::operator=(const
std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char, _Traits =
std::char_traits<char>]' is private
/usr/include/c++/3.2/bits/stl_vector.h:893: within this context

--------- Compilation : END -----------

--
==========================================
Alex Vinokur
mailto:al****@connect.to
http://www.simtel.net/pub/oth/19088.html
http://sourceforge.net/users/alexvn
==========================================
Jul 19 '05 #1
4 6173
Alex Vinokur wrote:
Is it possible to use vector<ostringstream> ?

Here is what I have got.

===========================================
Windows 2000
CYGWIN_NT-5.0 1.3.22(0.78/3/2)
GNU gcc version 3.2 20020927 (prerelease)
===========================================

// File t.cpp
--------- C++ code : BEGIN ---------
#include <vector>
#include <sstream>
#include <iostream>
using namespace std;

int main ()
{
vector<ostringstream> oss;

oss.push_back (ostringstream()); // Line#10
oss.front() << "ABCD" << endl;

cout << oss.front().str();

return 0;
}
--------- C++ code : END -----------


This is probably not what you truly want to do.

An ostringstream is probably not assignable, meaning you can't "push" them.

The code below blows up as well.

#include <sstream>
#include <iostream>
using namespace std;

int main ()
{

ostringstream a;
ostringstream b;

a = b;

return 0;
}

vector objects need to be assignable so you're going to have a hard time
with vector<ostringstream>.

You could create :

vector<ostringstream *>

But then you need to know how to delete them. One suggestion is to
create a class like:

class foo
: public ostringstream,
public lifetime_manager
{

};
class foo_pointer
{

foo * m_foo;

public:

operator ostringstream &()
{
return * m_foo;
}

.... all other reference counting smart pointer things like
constructors, destructors and assignment operators ... I can give you a
template for these ...

};
Now you can write

vector<foo_pointer> oss;

oss.push_back (new foo());

oss.front() << "ABCD" << endl;
I know it's a bit terse, but depending on what you truly trying to do,
you might have a more appropriate alternative.

G
Jul 19 '05 #2
"Alex Vinokur" <al****@bigfoot.com> writes:
Is it possible to use vector<ostringstream> ?
No. Vector element types have to be copyable, which stream types aren't.

/usr/include/c++/3.2/bits/ios_base.h:421: `std::ios_base::ios_base(const
std::ios_base&)' is private


This is how the "noncopyability" is implemented.
Jul 19 '05 #3
Alex Vinokur wrote:
Is it possible to use vector<ostringstream> ?
Nope, not like that. Never tried it myself until now but those errors are
basically telling you its impossible.
Here is what I have got.

===========================================
Windows 2000
CYGWIN_NT-5.0 1.3.22(0.78/3/2)
GNU gcc version 3.2 20020927 (prerelease)
===========================================

// File t.cpp
--------- C++ code : BEGIN ---------
#include <vector>
#include <sstream>
#include <iostream>
using namespace std;

int main ()
{
vector<ostringstream> oss;

oss.push_back (ostringstream()); // Line#10
oss.front() << "ABCD" << endl;

cout << oss.front().str();

return 0;
}


vector<string> methinks!
--
Guy Harrison
Jul 19 '05 #4
"Alex Vinokur" <al****@bigfoot.com> writes:
Is it possible to use vector<ostringstream> ?


No. ostringstream is not copyable.
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chris | last post by:
Hi, I'm playing/developing a simple p2p file sharing client for an existing protocol. A 2 second description of the protocol is Message Length = int, 4 bytes Message Code = int, 4 bytes...
8
by: Markus Dehmann | last post by:
I am wondering what is the "best" code to print out the elements of a vector. Assume they contain strings. With "best", I mean shortest and most readable at the same time. Of course, a for...
6
by: justyb11 | last post by:
Hello. I'm trying to use the following code but I continue to get Aborted as the output. Please note that this is compiled using gcc 3.3.4 on Linux 2.6.11.11 --- //file: vectest.cc ...
1
by: tim | last post by:
I am trying to convert numeric data held in a vector to a vector of string. The method is listed below. My compiler (VC6) reports the error "error C2227: left of '->data' must point to...
5
by: Minkoo Seo | last post by:
Hi list. I'd like to print a line "" given a vector<string> containing "A", "BC", "D", "EF". The following code is what I've written for this purpose: #include <iostream> #include <vector>
4
by: Bobrick | last post by:
Hi. I'm in the process of making a GUI for a function someone else wrote, and i've come across a type i'm unfamiliar with, namely "std::vector<unsigned char>". I need to get the contents of this...
10
by: Jess | last post by:
Hello, I have a program that stores dynamically created objects into a vector. #include<iostream> #include<vector> using namespace std;
5
by: yogi_bear_79 | last post by:
Below is a snippet of code that works for me. Currenlty it populates my vector with one digit per element. I would like to modify this code to populate each element of the vector with 3 digits...
10
by: oktayarslan | last post by:
Hi all; I have a problem when inserting an element to a vector. All I want is reading some data from a file and putting them into a vector. But the program is crashing after pushing a data which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.