473,395 Members | 1,783 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,395 software developers and data experts.

back_inserter() on strings

Joe Laughlin wrote:
Mike Wahler wrote:
"Joe Laughlin" <Jo***************@boeing.com> wrote in
message news:I6********@news.boeing.com... <snip>
Joe Laughlin wrote:
std::back_insert_iterator<std::string>::operator=( const
std::back_insert_iterator<std::string>&)


'back_insert_iterator' requires that the container type
specified by its template argument defines members
'push_back()' and 'value_type'. 'std::string' defines the
latter, but not the former.

IOW you cannot use 'back_insert_iterator' with a
'std::string'. ('std::string', while sharing much
commonality with them, isn't strictly a 'container').

-Mike


Argh.

From "Accelerated C++", pg 121:

"back_inserter(c)
Yields an iterator on the container c that appends
elements to c. The container must support push_back,
which the list, vector, and the string types all do."


Was the book wrong? Or am I reading it wrong?
Jul 22 '05 #1
2 4570
Joe Laughlin wrote:
Joe Laughlin wrote:
Mike Wahler wrote:
"Joe Laughlin" <Jo***************@boeing.com> wrote in
message news:I6********@news.boeing.com...
<snip>
Joe Laughlin wrote:
std::back_insert_iterator<std::string>::operat or=(const
std::back_insert_iterator<std::string>&)

'back_insert_iterator' requires that the container type
specified by its template argument defines members
'push_back()' and 'value_type'. 'std::string' defines the
latter, but not the former.

IOW you cannot use 'back_insert_iterator' with a
'std::string'. ('std::string', while sharing much
commonality with them, isn't strictly a 'container').

-Mike


Argh.

From "Accelerated C++", pg 121:

"back_inserter(c)
Yields an iterator on the container c that appends
elements to c. The container must support push_back,
which the list, vector, and the string types all do."

Was the book wrong? Or am I reading it wrong?


I can't attest to your reading of it, but the book is not wrong.

From the Standard, 21.3/2:
"The template class basic_string conforms to the requirements of
a Sequence, as specified in (23.1.1). Additionally, because the
iterators supported by basic_string are random access iterators
(24.1.5), basic_string conforms to the the requirements of
a Reversible Container, as specified in (23.1)."

IOW, a string _is_ a sequential container, no matter how much Mike may
want to make it sound that it isn't. Whatever _conforms_ to the
requirements for a container _is_ a container, as far as C++ is concerned.

V
Jul 22 '05 #2
On Tue, 26 Oct 2004 17:50:02 GMT, "Joe Laughlin"
<Jo***************@boeing.com> wrote:
Joe Laughlin wrote:
Mike Wahler wrote:
"Joe Laughlin" <Jo***************@boeing.com> wrote in
message news:I6********@news.boeing.com...<snip> Joe Laughlin wrote:
std::back_insert_iterator<std::string>::operator=( const
std::back_insert_iterator<std::string>&)

'back_insert_iterator' requires that the container type
specified by its template argument defines members
'push_back()' and 'value_type'. 'std::string' defines the
latter, but not the former.

IOW you cannot use 'back_insert_iterator' with a
'std::string'. ('std::string', while sharing much
commonality with them, isn't strictly a 'container').

-Mike


Argh.

From "Accelerated C++", pg 121:

"back_inserter(c)
Yields an iterator on the container c that appends
elements to c. The container must support push_back,
which the list, vector, and the string types all do."


Was the book wrong? Or am I reading it wrong?


The book is right - std::basic_string::push_back is standard. However,
VC6 has a pre-standard library in which std::string::push_back is not
present, which might be the source of the confusion.

Tom
Jul 22 '05 #3

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

Similar topics

20
by: Ravi | last post by:
Hi, I have about 200GB of data that I need to go through and extract the common first part of a line. Something like this. >>>a = "abcdefghijklmnopqrstuvwxyz" >>>b = "abcdefghijklmnopBHLHT"...
17
by: Gordon Airport | last post by:
Has anyone suggested introducing a mutable string type (yes, of course) and distinguishing them from standard strings by the quote type - single or double? As far as I know ' and " are currently...
8
by: Mark A. Gibbs | last post by:
I have a string conversion function that looks something like this (apologies, but I cannot post the actual code): whar_t char_to_wchar(char); wstring to_wstring(const string& s) { wstring...
3
by: silverburgh.meryl | last post by:
i have the following code, but it does not compile because I pass in back_inserter(b) as the output iterator in the remove_copy_if algorithm. My questions are: 1. why it does not compile? Passing...
1
by: Allerdyce.John | last post by:
Can I use back_inserter as the output iterator? The following code wont't compile, is there a reason for that? How can I achieve what I want? (grow aList if needed) class build { public: A*...
6
by: Daniel T. | last post by:
The line marked (1) below compiles fine and does exactly what I would expect, but the line marked (2) does not compile at all on my system. error: variable or field 'bar' declared void My...
2
by: Potiuper | last post by:
Question: Is it possible to use a char pointer array ( char *<name> ) to read an array of strings from a file in C? Given: code is written in ANSI C; I know the exact nature of the strings to be...
17
by: Jess | last post by:
Hello, The iterator adaptor "back_inserter" takes a container and returns a iterator so that we can insert elements to the end of the container. Out of curiosity, I tried to look at what element...
95
by: hstagni | last post by:
Where can I find a library to created text-based windows applications? Im looking for a library that can make windows and buttons inside console.. Many old apps were make like this, i guess ...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.