G
Guest
I am learning STL with the book STL Tutorial and Reference guide (1 edition),
the following example don't run :
int main()
{
// Initialize array a with 10 integers:
int a[10] = {12, 3, 25, 7, 11, 213, 7, 123, 29, -31};
// Find the first element equal to 7 in the array:
int* ptr = find(&a[0], &a[10], 7);
assert(*ptr == 7 && *(ptr+1) == 11);
// Initialize list1 with the same integers as in array a:
list<int> list1(&a[0], &a[10]);
// Find the first element equal to 7 in list1:
list<int>::iterator i = find(list1.begin(),
list1.end(),7);
assert(*i == 7 && *(++i) == 11);
cout << "Type some characters, including an 'x' followed\n"
<< "by at least one nonwhite-space character: " << flush;
istream_iterator<char, ptrdiff_t> pant(cin);
istream_iterator<char, ptrdiff_t> eos;
find(pant, eos, 'x');
cout << "The first nonwhite-space character following\n"
<< "the first 'x' was '" << *(++pant) << "'." << endl;
return 0;
}
The compiler report the error:
c:\Documents and Settings\Administrator\My Documents\Visual Studio
Projects\basicoConsola\basicoConsola.cpp(27): error C2664:
'std::istream_iterator<_Ty,_Elem>::istream_iterator(std::istream_iterator<_Ty,_Elem>::istream_type
&)' : no se puede convertir el parámetro 1 de 'std::istream' a
'std::istream_iterator<_Ty,_Elem>::istream_type &'
with
[
_Ty=char,
_Elem=ptrdiff_t
]
and
[
_Ty=char,
_Elem=ptrdiff_t
]
I use Microsoft Visual C++ .NET 2003, the C++ proyect is simple ( no .NET)
is win32 with output to screen.
the following example don't run :
int main()
{
// Initialize array a with 10 integers:
int a[10] = {12, 3, 25, 7, 11, 213, 7, 123, 29, -31};
// Find the first element equal to 7 in the array:
int* ptr = find(&a[0], &a[10], 7);
assert(*ptr == 7 && *(ptr+1) == 11);
// Initialize list1 with the same integers as in array a:
list<int> list1(&a[0], &a[10]);
// Find the first element equal to 7 in list1:
list<int>::iterator i = find(list1.begin(),
list1.end(),7);
assert(*i == 7 && *(++i) == 11);
cout << "Type some characters, including an 'x' followed\n"
<< "by at least one nonwhite-space character: " << flush;
istream_iterator<char, ptrdiff_t> pant(cin);
istream_iterator<char, ptrdiff_t> eos;
find(pant, eos, 'x');
cout << "The first nonwhite-space character following\n"
<< "the first 'x' was '" << *(++pant) << "'." << endl;
return 0;
}
The compiler report the error:
c:\Documents and Settings\Administrator\My Documents\Visual Studio
Projects\basicoConsola\basicoConsola.cpp(27): error C2664:
'std::istream_iterator<_Ty,_Elem>::istream_iterator(std::istream_iterator<_Ty,_Elem>::istream_type
&)' : no se puede convertir el parámetro 1 de 'std::istream' a
'std::istream_iterator<_Ty,_Elem>::istream_type &'
with
[
_Ty=char,
_Elem=ptrdiff_t
]
and
[
_Ty=char,
_Elem=ptrdiff_t
]
I use Microsoft Visual C++ .NET 2003, the C++ proyect is simple ( no .NET)
is win32 with output to screen.