CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: going mad

  1. #1
    Join Date
    May 2000
    Location
    Germany
    Posts
    369

    going mad

    Hello!
    I try to use the stl::search function but i am not able to figure out the problem. I thing I know how to use this function because i have already used it sucessfully serveral times but now it doesn´t work.

    Code:
    #include <string>
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <fstream>
    
    using namespace std;
    
    int main()
    {
    	vector<string> vec(1);
    	vec[0] = "#include";
    
    	ifstream ifs( __FILE__ );
    	istream_iterator<string> is( ifs ), end;
    
    	//copy( is, end, ostream_iterator<string>(cout, "\n" ) );
    	istream_iterator<string> it = search( is, end, vec.begin(), vec.end() );
    
    	cout << it->c_str();
    
        return 0;
    }
    The stl::copy function works fine and outputs me the whole file but the search function doesn´t work.
    I tried to debug the function "search" and i saw that in the first loop the iterator "is" has a correct value but in the next loops the iterator "is" keeps always the value of a empty string.
    Can somone help me ?

    Thanks in advance
    Last edited by kakalake; March 25th, 2003 at 04:49 PM.

  2. #2
    Join Date
    May 2000
    Location
    Germany
    Posts
    369
    I found the error maybe.
    The istream_iterator is a input_iterator_tag and the function search uses the function _Distance (for-loop) to count the number of element inside the container. So the function _Distance puts the iterator (the filepointer) at the end of the file. Is this rigth???

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured