Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > weird error

Reply
Thread Tools

weird error

 
 
Joe Laughlin
Guest
Posts: n/a
 
      10-22-2004
Joe Laughlin wrote:
>


These weird errors just keep on coming! Thanks everyone again for your
help.

Please don't tell me this error is because of const again... But I'd
wager it is.


// 6-9 from Accelerated C++
// Use library algorithm to cat all elements of a vector<string>

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

int main()
{
std::vector<std::string> vec;
vec.push_back("Hi!");
vec.push_back(" How ");
vec.push_back("are ");
vec.push_back("you ");
vec.push_back("doing?");

std::string new_string;

copy(vec.begin(), vec.end(), std::back_inserter(new_string));

std::cout << new_string << std::endl;

return 0;
}


g++ -Wall -pedantic -o 6-9 6-9.cpp
/usr/include/c++/3.2.2/bits/stl_algobase.h: In function `_OutputIter
std::__copy(_RandomAccessIter, _RandomAccessIter, _OutputIter,
std::random_access_iterator_tag) [with _RandomAccessIter = std::string*,
_OutputIter = std::back_insert_iterator<std::string>]':
/usr/include/c++/3.2.2/bits/stl_algobase.h:260: instantiated from
`_OutputIter std::__copy_aux2(_InputIter, _InputIter, _
OutputIter, __false_type) [with _InputIter = std::string*, _OutputIter =
std::back_insert_iterator<std::string>]'
/usr/include/c++/3.2.2/bits/stl_algobase.h:303: instantiated from
`_OutputIter std::__copy_ni2(_InputIter, _InputIter, _O
utputIter, __false_type) [with _InputIter = std::string*, _OutputIter =
std::back_insert_iterator<std::string>]'
/usr/include/c++/3.2.2/bits/stl_algobase.h:314: instantiated from
`_OutputIter std::__copy_ni1(_InputIter, _InputIter, _O
utputIter, __true_type) [with _InputIter =
__gnu_cxx::__normal_iterator<std::string*, std::vector<std::string,
std::allocat
or<std::string> > >, _OutputIter = std::back_insert_iterator<std::string>]'
/usr/include/c++/3.2.2/bits/stl_algobase.h:349: instantiated from
`_OutputIter std::copy(_InputIter, _InputIter, _OutputI
ter) [with _InputIter = __gnu_cxx::__normal_iterator<std::string*,
std::vector<std::string, std::allocator<std::string> > >
, _OutputIter = std::back_insert_iterator<std::string>]'
6-9.cpp:22: instantiated from here
/usr/include/c++/3.2.2/bits/stl_algobase.h:241: no match for `
std::back_insert_iterator<std::string>& = std::basic_string<char,
std::char_traits<char>, std::allocator<char> >&' operator
/usr/include/c++/3.2.2/bits/stl_iterator.h:355: candidates are:
std::back_insert_iterator<_Container>&

std::back_insert_iterator<_Container>:perator=(_ Container::const_reference
)
[with _Container = std::string]
/usr/include/c++/3.2.2/bits/stl_iterator.h:330:
std::back_insert_iterator<std::string>&
std::back_insert_iterator<std::string>:perator=( const
std::back_insert_iterator<std::string>&)


 
Reply With Quote
 
 
 
 
Mike Wahler
Guest
Posts: n/a
 
      10-23-2004

"Joe Laughlin" <> wrote in message
news:...
> Joe Laughlin wrote:
> >

>
> These weird errors just keep on coming! Thanks everyone again for your
> help.
>
> Please don't tell me this error is because of const again... But I'd
> wager it is.


Not this time.
See below.

> // 6-9 from Accelerated C++
> // Use library algorithm to cat all elements of a vector<string>
>
> #include <iostream>
> #include <vector>
> #include <string>
> #include <algorithm>
> #include <iterator>
>
> int main()
> {
> std::vector<std::string> vec;
> vec.push_back("Hi!");
> vec.push_back(" How ");
> vec.push_back("are ");
> vec.push_back("you ");
> vec.push_back("doing?");
>
> std::string new_string;
>
> copy(vec.begin(), vec.end(), std::back_inserter(new_string));
>
> std::cout << new_string << std::endl;
>
> return 0;
> }
>
>
> g++ -Wall -pedantic -o 6-9 6-9.cpp
> /usr/include/c++/3.2.2/bits/stl_algobase.h: In function `_OutputIter
> std::__copy(_RandomAccessIter, _RandomAccessIter, _OutputIter,
> std::random_access_iterator_tag) [with _RandomAccessIter =

std::string*,
> _OutputIter = std::back_insert_iterator<std::string>]':
> /usr/include/c++/3.2.2/bits/stl_algobase.h:260: instantiated from
> `_OutputIter std::__copy_aux2(_InputIter, _InputIter, _
> OutputIter, __false_type) [with _InputIter = std::string*, _OutputIter =
> std::back_insert_iterator<std::string>]'
> /usr/include/c++/3.2.2/bits/stl_algobase.h:303: instantiated from
> `_OutputIter std::__copy_ni2(_InputIter, _InputIter, _O
> utputIter, __false_type) [with _InputIter = std::string*, _OutputIter =
> std::back_insert_iterator<std::string>]'
> /usr/include/c++/3.2.2/bits/stl_algobase.h:314: instantiated from
> `_OutputIter std::__copy_ni1(_InputIter, _InputIter, _O
> utputIter, __true_type) [with _InputIter =
> __gnu_cxx::__normal_iterator<std::string*, std::vector<std::string,
> std::allocat
> or<std::string> > >, _OutputIter =

std::back_insert_iterator<std::string>]'
> /usr/include/c++/3.2.2/bits/stl_algobase.h:349: instantiated from
> `_OutputIter std::copy(_InputIter, _InputIter, _OutputI
> ter) [with _InputIter = __gnu_cxx::__normal_iterator<std::string*,
> std::vector<std::string, std::allocator<std::string> > >
> , _OutputIter = std::back_insert_iterator<std::string>]'
> 6-9.cpp:22: instantiated from here
> /usr/include/c++/3.2.2/bits/stl_algobase.h:241: no match for `
> std::back_insert_iterator<std::string>& = std::basic_string<char,
> std::char_traits<char>, std::allocator<char> >&' operator
> /usr/include/c++/3.2.2/bits/stl_iterator.h:355: candidates are:
> std::back_insert_iterator<_Container>&
>
>

std::back_insert_iterator<_Container>:perator=(_ Container::const_reference
> )
> [with _Container = std::string]
> /usr/include/c++/3.2.2/bits/stl_iterator.h:330:
> std::back_insert_iterator<std::string>&
> std::back_insert_iterator<std::string>:perator=( 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


 
Reply With Quote
 
 
 
 
Joe Laughlin
Guest
Posts: n/a
 
      10-23-2004
Mike Wahler wrote:
> "Joe Laughlin" <> wrote in
> message news:...
>> Joe Laughlin wrote:
>>>

>>
>> These weird errors just keep on coming! Thanks everyone
>> again for your help.
>>
>> Please don't tell me this error is because of const
>> again... But I'd wager it is.

>
> Not this time.
> See below.
>
>> // 6-9 from Accelerated C++
>> // Use library algorithm to cat all elements of a
>> vector<string>
>>
>> #include <iostream>
>> #include <vector>
>> #include <string>
>> #include <algorithm>
>> #include <iterator>
>>
>> int main()
>> {
>> std::vector<std::string> vec;
>> vec.push_back("Hi!");
>> vec.push_back(" How ");
>> vec.push_back("are ");
>> vec.push_back("you ");
>> vec.push_back("doing?");
>>
>> std::string new_string;
>>
>> copy(vec.begin(), vec.end(),
>> std::back_inserter(new_string));
>>
>> std::cout << new_string << std::endl;
>>
>> return 0;
>> }
>>
>>
>> g++ -Wall -pedantic -o 6-9 6-9.cpp
>> /usr/include/c++/3.2.2/bits/stl_algobase.h: In function
>> `_OutputIter std::__copy(_RandomAccessIter,
>> _RandomAccessIter, _OutputIter,
>> std::random_access_iterator_tag) [with
>> _RandomAccessIter = std::string*, _OutputIter =
>> std::back_insert_iterator<std::string>]':
>> /usr/include/c++/3.2.2/bits/stl_algobase.h:260:
>> instantiated from `_OutputIter
>> std::__copy_aux2(_InputIter, _InputIter, _
>> OutputIter, __false_type) [with _InputIter =
>> std::string*, _OutputIter =
>> std::back_insert_iterator<std::string>]'
>> /usr/include/c++/3.2.2/bits/stl_algobase.h:303:
>> instantiated from `_OutputIter
>> std::__copy_ni2(_InputIter, _InputIter, _O
>> utputIter, __false_type) [with _InputIter =
>> std::string*, _OutputIter =
>> std::back_insert_iterator<std::string>]'
>> /usr/include/c++/3.2.2/bits/stl_algobase.h:314:
>> instantiated from `_OutputIter
>> std::__copy_ni1(_InputIter, _InputIter, _O
>> utputIter, __true_type) [with _InputIter =
>> __gnu_cxx::__normal_iterator<std::string*,
>> std::vector<std::string, std::allocat
>> or<std::string> > >, _OutputIter =

> std::back_insert_iterator<std::string>]'
>> /usr/include/c++/3.2.2/bits/stl_algobase.h:349:
>> instantiated from `_OutputIter std::copy(_InputIter,
>> _InputIter, _OutputI
>> ter) [with _InputIter =
>> __gnu_cxx::__normal_iterator<std::string*,
>> std::vector<std::string, std::allocator<std::string> > >
>> , _OutputIter = std::back_insert_iterator<std::string>]'
>> 6-9.cpp:22: instantiated from here
>> /usr/include/c++/3.2.2/bits/stl_algobase.h:241: no
>> match for ` std::back_insert_iterator<std::string>& =
>> std::basic_string<char, std::char_traits<char>,
>> std::allocator<char> >&' operator
>> /usr/include/c++/3.2.2/bits/stl_iterator.h:355:
>> candidates are: std::back_insert_iterator<_Container>&
>>
>>

>

std::back_insert_iterator<_Container>:perator=(_ Container::const_reference
>> )
>> [with _Container = std::string]
>> /usr/include/c++/3.2.2/bits/stl_iterator.h:330:
>> std::back_insert_iterator<std::string>&
>>
>>
>> std::back_insert_iterator<std::string>:perator=( 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."


 
Reply With Quote
 
Joe Laughlin
Guest
Posts: n/a
 
      10-25-2004
Joe Laughlin wrote:
> Mike Wahler wrote:
>> "Joe Laughlin" <> wrote in
>> message news:...
>>> Joe Laughlin wrote:
>>>>
>>>
>>> These weird errors just keep on coming! Thanks everyone
>>> again for your help.
>>>
>>> Please don't tell me this error is because of const
>>> again... But I'd wager it is.

>>
>> Not this time.
>> See below.
>>
>>> // 6-9 from Accelerated C++
>>> // Use library algorithm to cat all elements of a
>>> vector<string>
>>>
>>> #include <iostream>
>>> #include <vector>
>>> #include <string>
>>> #include <algorithm>
>>> #include <iterator>
>>>
>>> int main()
>>> {
>>> std::vector<std::string> vec;
>>> vec.push_back("Hi!");
>>> vec.push_back(" How ");
>>> vec.push_back("are ");
>>> vec.push_back("you ");
>>> vec.push_back("doing?");
>>>
>>> std::string new_string;
>>>
>>> copy(vec.begin(), vec.end(),
>>> std::back_inserter(new_string));
>>>
>>> std::cout << new_string << std::endl;
>>>
>>> return 0;
>>> }
>>>
>>>
>>> g++ -Wall -pedantic -o 6-9 6-9.cpp
>>> /usr/include/c++/3.2.2/bits/stl_algobase.h: In function
>>> `_OutputIter std::__copy(_RandomAccessIter,
>>> _RandomAccessIter, _OutputIter,
>>> std::random_access_iterator_tag) [with
>>> _RandomAccessIter = std::string*, _OutputIter =
>>> std::back_insert_iterator<std::string>]':
>>> /usr/include/c++/3.2.2/bits/stl_algobase.h:260:
>>> instantiated from `_OutputIter
>>> std::__copy_aux2(_InputIter, _InputIter, _
>>> OutputIter, __false_type) [with _InputIter =
>>> std::string*, _OutputIter =
>>> std::back_insert_iterator<std::string>]'
>>> /usr/include/c++/3.2.2/bits/stl_algobase.h:303:
>>> instantiated from `_OutputIter
>>> std::__copy_ni2(_InputIter, _InputIter, _O
>>> utputIter, __false_type) [with _InputIter =
>>> std::string*, _OutputIter =
>>> std::back_insert_iterator<std::string>]'
>>> /usr/include/c++/3.2.2/bits/stl_algobase.h:314:
>>> instantiated from `_OutputIter
>>> std::__copy_ni1(_InputIter, _InputIter, _O
>>> utputIter, __true_type) [with _InputIter =
>>> __gnu_cxx::__normal_iterator<std::string*,
>>> std::vector<std::string, std::allocat
>>> or<std::string> > >, _OutputIter =

>> std::back_insert_iterator<std::string>]'
>>> /usr/include/c++/3.2.2/bits/stl_algobase.h:349:
>>> instantiated from `_OutputIter std::copy(_InputIter,
>>> _InputIter, _OutputI
>>> ter) [with _InputIter =
>>> __gnu_cxx::__normal_iterator<std::string*,
>>> std::vector<std::string, std::allocator<std::string> > >
>>> , _OutputIter = std::back_insert_iterator<std::string>]'
>>> 6-9.cpp:22: instantiated from here
>>> /usr/include/c++/3.2.2/bits/stl_algobase.h:241: no
>>> match for ` std::back_insert_iterator<std::string>& =
>>> std::basic_string<char, std::char_traits<char>,
>>> std::allocator<char> >&' operator
>>> /usr/include/c++/3.2.2/bits/stl_iterator.h:355:
>>> candidates are: std::back_insert_iterator<_Container>&
>>>
>>>

>>

>

std::back_insert_iterator<_Container>:perator=(_ Container::const_reference
>>> )
>>> [with _Container = std::string]
>>> /usr/include/c++/3.2.2/bits/stl_iterator.h:330:
>>> std::back_insert_iterator<std::string>&
>>>
>>>
>>> std::back_insert_iterator<std::string>:perator=( 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."


So, was the book correct? Or wrong?


 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      10-26-2004
"Joe Laughlin" <> wrote in message
news:...
> Joe Laughlin wrote:
> >
> > 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."

>
> So, was the book correct? Or wrong?


I think it's wrong. As far as I can tell from the standard,
'std::basic_string<>' is not required to provide 'push_back()',
but neither is it prohibited from doing so.

Of course I invite anyone else to give their interpretation,
so we can know for sure.

I scanned the AC++ errata pages, but I don't see this issue
mentioned.

Anyone else?

-Mike


 
Reply With Quote
 
Buster
Guest
Posts: n/a
 
      10-26-2004
Mike Wahler wrote:
> "Joe Laughlin" <> wrote in message
> news:...
>
>>Joe Laughlin wrote:
>>
>>>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."

>>
>>So, was the book correct? Or wrong?

>
>
> I think it's wrong. As far as I can tell from the standard,
> 'std::basic_string<>' is not required to provide 'push_back()',
> but neither is it prohibited from doing so.


ISO/IEC 14882 1998, p385

// 21.3.5: modifiers
....
void push_back (charT);

>
> Of course I invite anyone else to give their interpretation,
> so we can know for sure.
>
> I scanned the AC++ errata pages, but I don't see this issue
> mentioned.
>
> Anyone else?

 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      10-27-2004

"Buster" <> wrote in message
news:clm1lp$849$...
> Mike Wahler wrote:
> > "Joe Laughlin" <> wrote in message
> > news:...


> > I think it's wrong. As far as I can tell from the standard,
> > 'std::basic_string<>' is not required to provide 'push_back()',
> > but neither is it prohibited from doing so.

>
> ISO/IEC 14882 1998, p385
>
> // 21.3.5: modifiers
> ...
> void push_back (charT);


But that's the *only* mention of it. For all the other
member functions, there is a description of behavior.
Not for this one. ???

-Mike


 
Reply With Quote
 
Rob Williscroft
Guest
Posts: n/a
 
      10-27-2004
Mike Wahler wrote in news:6fRfd.4096$kM.1575
@newsread3.news.pas.earthlink.net in comp.lang.c++:

>
> "Buster" <> wrote in message
> news:clm1lp$849$...
>> Mike Wahler wrote:
>> > "Joe Laughlin" <> wrote in message
>> > news:...

>
>> > I think it's wrong. As far as I can tell from the standard,
>> > 'std::basic_string<>' is not required to provide 'push_back()',
>> > but neither is it prohibited from doing so.

>>
>> ISO/IEC 14882 1998, p385
>>
>> // 21.3.5: modifiers
>> ...
>> void push_back (charT);

>
> But that's the *only* mention of it. For all the other
> member functions, there is a description of behavior.
> Not for this one. ???
>


21.3/2

The class template 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).

Table 68 - Optional Sequence operations (23.1.1/12) describes push_back.
Presunmably its only because its optional that its mentioned in 21.3.5
at all.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
 
Reply With Quote
 
Jerry Coffin
Guest
Posts: n/a
 
      10-28-2004
"Mike Wahler" <> wrote in message news:<6fRfd.4096$ ink.net>...

[ ... ]

> > // 21.3.5: modifiers
> > ...
> > void push_back (charT);

>
> But that's the *only* mention of it. For all the other
> member functions, there is a description of behavior.
> Not for this one. ???


Theoretically, it's handled by ($21.3/2):

The template class basic_string conforms to the requirements
of a Sequence, as specified in (23.1.1).

Unfortunately, 23.1.1/12 also only mentions the existence of
push_back, and leaves describing it in any detail for the individual
container classes that provide it -- but (of course) not including
string...

--
Later,
Jerry.

The universe is a figment of its own imagination.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: A Weird Appearance for a Weird Site David Segall HTML 0 01-22-2011 04:50 AM
Re: A Weird Appearance for a Weird Site Beauregard T. Shagnasty HTML 1 01-21-2011 04:17 PM
Re: A Weird Appearance for a Weird Site richard HTML 0 01-21-2011 07:10 AM
Re: A Weird Appearance for a Weird Site dorayme HTML 1 01-21-2011 06:51 AM
Re: A Weird Appearance for a Weird Site richard HTML 0 01-21-2011 06:46 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57