A
arnuld
I know the line which causes the error but unable to find out the why. The
line in STEP 4, "std:stream_iterator<stint>( std::cout, "\n" ), is the
source of error:
/* C++ Primer - 4/e
*
* CHAPTER 10 - Associative Containers
*
* EXERCISE - 10.1
* Write a program to read a sequence of strings and ints, storing
* each into a pair. Store the pairs into a Vector.
*
*/
/* We will solve this problem in 4 steps
1.) Define all the variables we need.
2.) Get input and store that into the pair.
3.) store the respective pair into the Vector.
4.) print the vector ( to see if the program really worked or not).
*/
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <iterator>
int main()
{
/* STEP 1
each pair will represent a string as first member connected to an int
as second memeber.
*/
typedef std:air<std::string, int> stint;
std::vector<stint> vec_stint;
/* STEP 2 & 3 */
std::string ele1;
int ele2;
std::cout << "Please enter a word at 1st input and
a number at 2nd iput and so on"
<< std::endl;
while( std::cin >> ele1 >> ele2 )
{
stint current_stint = make_pair( ele1, ele2 );
vec_stint.push_back(current_stint );
}
/* STEP 4 */
std::copy( vec_stint.begin(), vec_stint.end(),
std:stream_iterator<stint>( std::cout, "\n" ));
return 0;
}
========= OUTPUT ===============
[arnuld@gnu programs]$ g++ -ansi -pedantic -Wall -Wextra 10.01.cpp
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.2.2/../../../../include/c++/4.2.2/bits/stream_iterator.h:
In member function ‘std:stream_iterator<_Tp, _CharT, _Traits>&
std:stream_iterator<_Tp, _CharT, _Traits>:perator=(const _Tp&) [with
_Tp = std:air<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, int>, _CharT = char, _Traits =
std::char_traits<char>]’:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.2.2/../../../../include/c++/4.2.2/bits/stl_algobase.h:283:
instantiated from ‘static _OI std::__copy<_BoolType,
std::random_access_iterator_tag>::copy(_II, _II, _OI) [with _II =
std:air<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, int>*, _OI =
std:stream_iterator<std:air<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int>, char,
std::char_traits<char> >, bool _BoolType = false]’
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.2.2/../../../../include/c++/4.2.2/bits/stl_algobase.h:315:
instantiated from ‘_OI std::__copy_aux(_II, _II, _OI) [with _II =
std:air<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, int>*, _OI =
std:stream_iterator<std:air<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int>, char,
std::char_traits<char> >]’
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.2.2/../../../../include/c++/4.2.2/bits/stl_algobase.h:349:
instantiated from ‘static _OI std::__copy_normal<true,
false>::__copy_n(_II, _II, _OI) [with _II =
__gnu_cxx::__normal_iterator<std:air<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int>*,
std::vector<std:air<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, int>,
std::allocator<std:air<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, int> > > >, _OI =
std:stream_iterator<std:air<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int>, char,
std::char_traits<char> >]’
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.2.2/../../../../include/c++/4.2.2/bits/stl_algobase.h:401:
instantiated from ‘_OutputIterator std::copy(_InputIterator,
_InputIterator, _OutputIterator) [with _InputIterator =
__gnu_cxx::__normal_iterator<std:air<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int>*,
std::vector<std:air<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, int>,
std::allocator<std:air<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, int> > > >, _OutputIterator =
std:stream_iterator<std:air<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int>, char,
std::char_traits<char> >]’ 10.01.cpp:51: instantiated from here
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.2.2/../../../../include/c++/4.2.2/bits/stream_iterator.h:196:
error: no match for ‘operator<<’ in
‘*((std:stream_iterator<std:air<std::basic_string<char,
std::char_traits<char> >::_M_stream << __value’
line in STEP 4, "std:stream_iterator<stint>( std::cout, "\n" ), is the
source of error:
/* C++ Primer - 4/e
*
* CHAPTER 10 - Associative Containers
*
* EXERCISE - 10.1
* Write a program to read a sequence of strings and ints, storing
* each into a pair. Store the pairs into a Vector.
*
*/
/* We will solve this problem in 4 steps
1.) Define all the variables we need.
2.) Get input and store that into the pair.
3.) store the respective pair into the Vector.
4.) print the vector ( to see if the program really worked or not).
*/
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <iterator>
int main()
{
/* STEP 1
each pair will represent a string as first member connected to an int
as second memeber.
*/
typedef std:air<std::string, int> stint;
std::vector<stint> vec_stint;
/* STEP 2 & 3 */
std::string ele1;
int ele2;
std::cout << "Please enter a word at 1st input and
a number at 2nd iput and so on"
<< std::endl;
while( std::cin >> ele1 >> ele2 )
{
stint current_stint = make_pair( ele1, ele2 );
vec_stint.push_back(current_stint );
}
/* STEP 4 */
std::copy( vec_stint.begin(), vec_stint.end(),
std:stream_iterator<stint>( std::cout, "\n" ));
return 0;
}
========= OUTPUT ===============
[arnuld@gnu programs]$ g++ -ansi -pedantic -Wall -Wextra 10.01.cpp
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.2.2/../../../../include/c++/4.2.2/bits/stream_iterator.h:
In member function ‘std:stream_iterator<_Tp, _CharT, _Traits>&
std:stream_iterator<_Tp, _CharT, _Traits>:perator=(const _Tp&) [with
_Tp = std:air<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, int>, _CharT = char, _Traits =
std::char_traits<char>]’:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.2.2/../../../../include/c++/4.2.2/bits/stl_algobase.h:283:
instantiated from ‘static _OI std::__copy<_BoolType,
std::random_access_iterator_tag>::copy(_II, _II, _OI) [with _II =
std:air<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, int>*, _OI =
std:stream_iterator<std:air<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int>, char,
std::char_traits<char> >, bool _BoolType = false]’
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.2.2/../../../../include/c++/4.2.2/bits/stl_algobase.h:315:
instantiated from ‘_OI std::__copy_aux(_II, _II, _OI) [with _II =
std:air<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, int>*, _OI =
std:stream_iterator<std:air<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int>, char,
std::char_traits<char> >]’
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.2.2/../../../../include/c++/4.2.2/bits/stl_algobase.h:349:
instantiated from ‘static _OI std::__copy_normal<true,
false>::__copy_n(_II, _II, _OI) [with _II =
__gnu_cxx::__normal_iterator<std:air<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int>*,
std::vector<std:air<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, int>,
std::allocator<std:air<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, int> > > >, _OI =
std:stream_iterator<std:air<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int>, char,
std::char_traits<char> >]’
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.2.2/../../../../include/c++/4.2.2/bits/stl_algobase.h:401:
instantiated from ‘_OutputIterator std::copy(_InputIterator,
_InputIterator, _OutputIterator) [with _InputIterator =
__gnu_cxx::__normal_iterator<std:air<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int>*,
std::vector<std:air<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, int>,
std::allocator<std:air<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, int> > > >, _OutputIterator =
std:stream_iterator<std:air<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int>, char,
std::char_traits<char> >]’ 10.01.cpp:51: instantiated from here
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.2.2/../../../../include/c++/4.2.2/bits/stream_iterator.h:196:
error: no match for ‘operator<<’ in
‘*((std:stream_iterator<std:air<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, int>, char,std::allocator<char> > said:*)this)->std:stream_iterator<std:air<std::basic_string<char,
std::char_traits<char> >::_M_stream << __value’