Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / December 2004

Tip: Looking for answers? Try searching our database.

istream_iterator<char, ptrdiff_t> fails

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
alberto - 21 Dec 2004 15:53 GMT
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.
Carl Daniel [VC++ MVP] - 21 Dec 2004 16:09 GMT
> I am learning STL with the book STL Tutorial and Reference guide (1
> edition),
> the following example don't run :

missing #includes and using declaration assumed...

> int main()
> {
[quoted text clipped - 20 lines]
>  istream_iterator<char, ptrdiff_t> pant(cin);
>  istream_iterator<char, ptrdiff_t> eos;

istream_iterator<char> pant(cin);
istream_iterator<char> eos;

>  find(pant, eos, 'x');
>
>  cout << "The first nonwhite-space character following\n"
>       << "the first 'x' was '" << *(++pant) << "'." << endl;
> return 0;
> }

-cd
alberto - 25 Dec 2004 17:53 GMT
Thanks!!

> > I am learning STL with the book STL Tutorial and Reference guide (1
> > edition),
[quoted text clipped - 38 lines]
>
> -cd

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.