N
Nomak
Hello,
With this code:
$ cat -n ifs.cc
1 #include <vector>
2 #include <iostream>
3
4 using std::vector;
5 using std::cin;
6
7 int
8 main()
9 {
10 vector< bool > vb(1);
11 vector< int > vi(1);
12 bool b;
13 int i;
14
15 cin >> b;
16 cin >> i;
17 cin >> (vb[0]);
18 cin >> (vi[0]);
19 return 0;
20 }
I have the following errors:
$ g++-2.95.3 -Wall ifs.cc
ifs.cc: In function `int main()':
ifs.cc:17: initialization of non-const reference type `bool &'
ifs.cc:17: from rvalue of type `bool'
/.../iostream.h:217: in passing argument 1 of `istream:perator
$ g++-3.3.2 -Wall ifs.cc
ifs.cc: In function `int main()':
ifs.cc:17: error: no match for 'operator>>' in 'std::cin >>
std::vector<bool, _Alloc>:perator[](unsigned int) [with _Alloc =
std::allocator<bool>](0)'
$ g++-3.4.0 -Wall ifs.cc
ifs.cc: In function `int main()':
ifs.cc:17: error: no match for 'operator>>' in 'std::cin >>
(&vb)->std::vector<bool, _Alloc>:perator[] [with _Alloc =
std::allocator<bool>](0u)'
$ g++-3.4.1 -Wall ifs.cc
ifs.cc: In function `int main()':
ifs.cc:17: error: no match for 'operator>>' in 'std::cin >>
(&vb)->std::vector<bool, _Alloc>:perator[] [with _Alloc =
std::allocator<bool>](0u)'
So i guess this is the good behavior, but does anybody have a
rationale for that? Why can i read into an int vector but not a bool
one??
With this code:
$ cat -n ifs.cc
1 #include <vector>
2 #include <iostream>
3
4 using std::vector;
5 using std::cin;
6
7 int
8 main()
9 {
10 vector< bool > vb(1);
11 vector< int > vi(1);
12 bool b;
13 int i;
14
15 cin >> b;
16 cin >> i;
17 cin >> (vb[0]);
18 cin >> (vi[0]);
19 return 0;
20 }
I have the following errors:
$ g++-2.95.3 -Wall ifs.cc
ifs.cc: In function `int main()':
ifs.cc:17: initialization of non-const reference type `bool &'
ifs.cc:17: from rvalue of type `bool'
/.../iostream.h:217: in passing argument 1 of `istream:perator
$ g++-3.3.2 -Wall ifs.cc
ifs.cc: In function `int main()':
ifs.cc:17: error: no match for 'operator>>' in 'std::cin >>
std::vector<bool, _Alloc>:perator[](unsigned int) [with _Alloc =
std::allocator<bool>](0)'
$ g++-3.4.0 -Wall ifs.cc
ifs.cc: In function `int main()':
ifs.cc:17: error: no match for 'operator>>' in 'std::cin >>
(&vb)->std::vector<bool, _Alloc>:perator[] [with _Alloc =
std::allocator<bool>](0u)'
$ g++-3.4.1 -Wall ifs.cc
ifs.cc: In function `int main()':
ifs.cc:17: error: no match for 'operator>>' in 'std::cin >>
(&vb)->std::vector<bool, _Alloc>:perator[] [with _Alloc =
std::allocator<bool>](0u)'
So i guess this is the good behavior, but does anybody have a
rationale for that? Why can i read into an int vector but not a bool
one??